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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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...