Changeset 389 for vtcross/trunk/src/lib/socketcomm
- Timestamp:
- 07/28/09 23:23:14 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
r232 r389 34 34 // TODO also, it appears that this function can, at maximum, receive 256 bytes 35 35 // without causing a buffer overflow. can someone confirm/deny? 36 void 36 int32_t 37 37 ReadMessage(int32_t socketFD, char* msgBuffer) 38 38 { … … 41 41 // Messages are termination with a "\0" to denote EOM. 42 42 ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK); 43 if(msgLength < 0)44 ERROR(1, "Error reading from socket.\n");45 if(msgLength == 0)46 ERROR(1, "Remote component closed connection. 1\n");47 43 if(msgLength <= 0) { 44 //ERROR(1, "Remote component closed connection. 1\n"); 45 //LOG("Client closed connection.\n"); 46 return -1; 47 } 48 48 size_t i; 49 49 for(i = 0; i < 256; i++) { … … 54 54 // Read the message into msgBuffer 55 55 msgLength = recv(socketFD, msgBuffer, i + 1, 0); 56 if(msgLength < 0) 57 ERROR(1, "Error reading from socket.\n"); 58 if(msgLength == 0) 59 ERROR(1, "Remote component closed connection. 2\n"); 56 if(msgLength <= 0) { 57 //ERROR(1, "Remote component closed connection. 1\n"); 58 //LOG("Client closed connection.\n"); 59 return -1; 60 } 61 62 return 1; 60 63 } 61 64 … … 93 96 94 97 95 /* TODO I'm fairly certain this function is unnecessary, see function below for more details...96 int32_t97 SendMessage(int32_t socketFD, char* message)98 {99 100 // TODO explain this. What, exactly, does the below line do and how does it101 // affect the rest of the function?102 strcat(message, "\0000");103 104 ssize_t numSentBytes = send(socketFD, message, (strlen(message) + 1), 0);105 if(numSentBytes < 0) {106 ERROR(1, "Error sending to server.");107 }108 else if(numSentBytes == 0) {109 LOG("socket_comm::SendMessage - Server closed the socket.\n");110 }111 112 return numSentBytes;113 }114 */115 116 98 // TODO this function is here to handle calls to send const char* messages. Note 117 99 // that the std::string.c_str() function auto-appends a null character at the … … 217 199 if(clientSocket < 0) { 218 200 //WARNING("ALERT: Could not establish connection with client socket.\n"); 219 return -1;201 return clientSocket; 220 202 } 221 203 //LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr));