Changeset 207 for vtcross/trunk/src/lib

Show
Ignore:
Timestamp:
03/26/09 10:40:14 (15 years ago)
Author:
jgaeddert
Message:

Added CognitiveRadioShell? class and Shell demo.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/lib/socketcomm/socketcomm.cpp

    r195 r207  
    1212#include <cstdlib> 
    1313#include <cstring> 
     14#include <iostream> 
     15#include <fcntl.h> 
     16#include <sys/ioctl.h> 
    1417#include <netdb.h> 
    1518#include <netinet/in.h> 
     
    3437ReadMessage(int32_t socketFD, char* msgBuffer) 
    3538{ 
     39 
     40    // Peek at the buffer to get real message length. 
     41    // Messages are termination with a "\0" to denote EOM. 
    3642    ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK); 
    3743 
     
    4248    } 
    4349 
     50    // Read the message into msgBuffer 
    4451    msgLength = recv(socketFD, msgBuffer, i + 1, 0); 
    4552    if (msgLength < 0) 
     
    202209 
    203210    int32_t clientSocket = accept(serverSock, NULL, NULL); 
    204     if(clientSocket < 0) 
    205         ERROR(1, "Could not establish connection with client socket.\n"); 
    206     
    207     LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr)); 
     211    if(clientSocket < 0) {  
     212        //ERROR(1, "Could not establish connection with client socket.\n"); 
     213        return -1; 
     214    } 
     215    //LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr)); 
    208216 
    209217    return clientSocket; 
     
    238246} 
    239247 
     248int32_t 
     249InitializeTCPServerPort(int32_t servSock) 
     250{ 
     251 
     252    int32_t rc, on = 1; 
     253 
     254    rc = setsockopt(servSock, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)); 
     255    if(rc < 0) 
     256    { 
     257        ERROR(1,"setsockopt() failed\n"); 
     258        close(servSock); 
     259        return -1; 
     260    } 
     261 
     262    rc = ioctl(servSock, FIONBIO, (char*)&on); 
     263    if(rc < 0) 
     264    { 
     265        ERROR(1,"ioctl() failed\n"); 
     266        close(servSock); 
     267        return -1; 
     268    } 
     269 
     270    return 1; 
     271}