Changeset 207 for vtcross/trunk/src/lib
- Timestamp:
- 03/26/09 10:40:14 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
r195 r207 12 12 #include <cstdlib> 13 13 #include <cstring> 14 #include <iostream> 15 #include <fcntl.h> 16 #include <sys/ioctl.h> 14 17 #include <netdb.h> 15 18 #include <netinet/in.h> … … 34 37 ReadMessage(int32_t socketFD, char* msgBuffer) 35 38 { 39 40 // Peek at the buffer to get real message length. 41 // Messages are termination with a "\0" to denote EOM. 36 42 ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK); 37 43 … … 42 48 } 43 49 50 // Read the message into msgBuffer 44 51 msgLength = recv(socketFD, msgBuffer, i + 1, 0); 45 52 if (msgLength < 0) … … 202 209 203 210 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)); 208 216 209 217 return clientSocket; … … 238 246 } 239 247 248 int32_t 249 InitializeTCPServerPort(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 }