Changeset 184

Show
Ignore:
Timestamp:
03/22/09 15:00:48 (15 years ago)
Author:
bhilburn
Message:

Added a new CreateClientSocket? function, using the new RemoteComponent? struct
type, to replace the old ClientSocket? function. Note that the old function is
left in until the new stuff gets tested and reviewed.

Location:
vtcross/trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/include/vtcross/containers.h

    r183 r184  
    8181 * that this information is independent of component type, but technically will 
    8282 * 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. 
    8386 */ 
    8487struct RemoteComponent { 
    8588    struct hostent *server; 
    8689    std::string serverName; 
    87     std::string serverPort; 
     90    int32_t serverPort; 
    8891    int32_t socketFD; 
    8992}; 
  • vtcross/trunk/src/include/vtcross/socketcomm.h

    r180 r184  
    1313#include <stdint.h> 
    1414 
     15#include "vtcross/containers.h" 
     16 
    1517 
    1618/* TODO 
    1719 */ 
    1820void ReadMessage(int32_t socketFD, char* msgBuffer); 
    19  
    20  
    21 /* TODO 
    22  */ 
    23 int32_t ClientSocket(const char* serverName, const char* portNumber); 
    2421 
    2522 
     
    4340 
    4441/* 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 */ 
     46void CreateClientSocket(struct RemoteComponent* serverInfo); 
     47 
     48 
     49/* This is the original function that does what the above function is supposed 
     50 * to do. 
     51 */ 
     52int32_t ClientSocket(const char* serverName, const char* portNumber); 
     53 
     54 
     55/* TODO 
    4556 */ 
    4657int32_t  AcceptTCPConnection(int32_t servSock); 
  • vtcross/trunk/src/lib/socketcomm/socketcomm.cpp

    r180 r184  
    7676} 
    7777 
     78 
     79/* TODO see notes in socketcomm.h. This function, and the RemoteComponent 
     80 * struct, need a code review. 
     81 */ 
     82void 
     83CreateClientSocket(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 
    78110     
    79111/* TODO I'm fairly certain this function is unnecessary, see function below for more details...