Changeset 64 for vtcross/branches

Show
Ignore:
Timestamp:
11/20/08 15:25:32 (16 years ago)
Author:
trnewman
Message:

Added better socket functionality.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp

    r63 r64  
    227227                n = recv(socketfd,buffer,255,0); 
    228228                if (n < 0) error("ERROR reading from socket"); 
    229                 if (n == 0) error("Client has closed the connection."); 
     229                if (n == 0) { 
     230                        printf("Client has closed the connection.\n"); 
     231                        return; 
     232                } 
    230233                 
    231234                // Print message 
     
    257260        listen(sockfd,5); 
    258261        clilen = sizeof(cli_addr); 
    259         newsockfd = accept(sockfd,  
    260                 (struct sockaddr *) &cli_addr,  
    261                 (socklen_t*)&clilen); 
    262         if (newsockfd < 0)  
    263                 error("ERROR on accept"); 
    264  
    265         // Begin parsing the messages 
    266         StartMessageParser(newsockfd); 
    267  
     262 
     263        while(1) { 
     264                newsockfd = accept(sockfd,  
     265                        (struct sockaddr *) &cli_addr,  
     266                        (socklen_t*)&clilen); 
     267                if (newsockfd < 0)  
     268                        error("ERROR on accept"); 
     269 
     270                // Begin parsing the messages 
     271                StartMessageParser(newsockfd); 
     272        } 
    268273        return 0; 
    269274} 
     
    275280        // CognitiveEngineShell Shell; 
    276281        string pFilename;  
     282        int pid; 
    277283 
    278284        Utility * uList[10]; 
     
    300306        cout << "Configuration file parsing completed." << endl; 
    301307 
    302         // Open cognitive engine port    
    303         StartShell(30000); 
    304  
    305         // Open policy engine port 
    306 //      StartShell(30001); 
     308        pid = fork(); 
     309        if(pid == 0) { 
     310                // In child process - open policy engine port. 
     311                StartShell(30001); 
     312        } else { 
     313                // In parent process - open cognitive engine port. 
     314                StartShell(30000); 
     315        }  
     316         
    307317 
    308318   return 1;