Definition at line 382 of file Channel.h. References HandleError(), mConnection, mIsServer, mMsgSock, mMsgSockEvent, mNrPorts, mPort, mServerName, mSock, mSockConnected, and mSockEvent. Referenced by Channel(). 00383 { 00384 #ifdef unix 00385 signal(SIGPIPE, SIG_IGN); // block broken pipe signal 00386 #else 00387 WORD wVersionRequested = MAKEWORD(1,1); 00388 WSADATA wsaData; 00389 00390 // Initialize WinSock and check version 00391 if (WSAStartup(wVersionRequested, &wsaData) != 0) 00392 HandleError("WSAStartup", true); 00393 00394 // Check socket DLL supports 1.1 or higher 00395 double socklib_ver = HIBYTE(wsaData.wVersion) / 10.0; 00396 socklib_ver += LOBYTE(wsaData.wVersion); 00397 if (socklib_ver < 1.1) 00398 HandleError("socket library must support 1.1 or greater", true); 00399 #endif 00400 00401 for (int i=0 ; i<mNrPorts ; i++) 00402 { 00403 struct sockaddr_in address; 00404 address.sin_family = AF_INET; 00405 address.sin_port = htons(mPort + i); 00406 struct hostent* hp; 00407 if (mIsServer) 00408 { 00409 address.sin_addr.s_addr = htonl(INADDR_ANY); 00410 } 00411 else 00412 { 00413 // gethostbyname returns a structure including the network 00414 // address of the specified host. 00415 if ((hp = gethostbyname(mServerName.c_str())) == NULL) 00416 HandleError("InitSocket: gethostbyname", true); 00417 // initialise the address structure with the resolved IP address 00418 memcpy((char *) &address.sin_addr, (char *) hp->h_addr, 00419 hp->h_length); 00420 } 00421 00422 SOCKET sock; 00423 // Create socket. 00424 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 00425 HandleError("InitSocket: open stream socket", true); 00426 if (mIsServer) 00427 { 00428 if (bind(sock, (struct sockaddr *) &address, 00429 sizeof(address)) == SOCKET_ERROR) 00430 { 00431 HandleError("InitSocket: bind socket", true); 00432 } 00433 } 00434 else 00435 { 00436 if (connect(sock, (struct sockaddr *) &address, 00437 sizeof(address)) == SOCKET_ERROR) 00438 { 00439 HandleError("InitSocket: connect socket", true); 00440 } 00441 } 00442 mSock.push_back(sock); 00443 mSockConnected.push_back(false); 00444 mConnection.push_back("not connected"); 00445 } 00446 mSockEvent.resize(mNrPorts); 00447 mMsgSock.resize(mNrPorts); 00448 mMsgSockEvent.resize(mNrPorts); 00449 }
Here is the call graph for this function:
|