Changeset 184 for vtcross/trunk/src
- Timestamp:
- 03/22/09 15:00:48 (15 years ago)
- Location:
- vtcross/trunk/src
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/include/vtcross/containers.h
r183 r184 81 81 * that this information is independent of component type, but technically will 82 82 * only ever be the SML or shell. 83 * 84 * TODO I'm not 100% certain I'm doing this in the most efficient way. Need 85 * someone to look it over. 83 86 */ 84 87 struct RemoteComponent { 85 88 struct hostent *server; 86 89 std::string serverName; 87 std::stringserverPort;90 int32_t serverPort; 88 91 int32_t socketFD; 89 92 }; -
vtcross/trunk/src/include/vtcross/socketcomm.h
r180 r184 13 13 #include <stdint.h> 14 14 15 #include "vtcross/containers.h" 16 15 17 16 18 /* TODO 17 19 */ 18 20 void ReadMessage(int32_t socketFD, char* msgBuffer); 19 20 21 /* TODO22 */23 int32_t ClientSocket(const char* serverName, const char* portNumber);24 21 25 22 … … 43 40 44 41 /* TODO 42 * This is meant as the future replacement for the function below it. It is 43 * still a work in progress, and needs a code-review before we move to it 44 * entirely. 45 */ 46 void CreateClientSocket(struct RemoteComponent* serverInfo); 47 48 49 /* This is the original function that does what the above function is supposed 50 * to do. 51 */ 52 int32_t ClientSocket(const char* serverName, const char* portNumber); 53 54 55 /* TODO 45 56 */ 46 57 int32_t AcceptTCPConnection(int32_t servSock); -
vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
r180 r184 76 76 } 77 77 78 79 /* TODO see notes in socketcomm.h. This function, and the RemoteComponent 80 * struct, need a code review. 81 */ 82 void 83 CreateClientSocket(struct RemoteComponent* serverInfo) 84 { 85 if(serverInfo == NULL) 86 ERROR(1, "CreateClientSocket received null struct pointer.\n"); 87 88 struct hostent *server = gethostbyname(serverInfo->serverName.c_str()); 89 if(server == NULL) 90 ERROR(1, "No server found by that hostname."); 91 92 memcpy(serverInfo, server, sizeof(struct hostent)); 93 94 serverInfo->socketFD = socket(AF_INET, SOCK_STREAM, 0); 95 if(serverInfo->socketFD < 0) 96 ERROR(1, "Error opening socket"); 97 98 struct sockaddr_in serv_addr; 99 memset((void *) &serv_addr, 0, sizeof(serv_addr)); 100 serv_addr.sin_family = AF_INET; 101 serv_addr.sin_port = htons(serverInfo->serverPort); 102 memcpy((char *) &serv_addr.sin_addr.s_addr, (char *) server->h_addr, \ 103 server->h_length); 104 105 if(connect(serverInfo->socketFD, (struct sockaddr *) &serv_addr, \ 106 sizeof(serv_addr)) < 0) 107 ERROR(1, "Error connecting to remote socket."); 108 } 109 78 110 79 111 /* TODO I'm fairly certain this function is unnecessary, see function below for more details...