Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

SOCKET Impala::Application::SDash::AlertRelay::SetupListening ( const std::string &  ipAddress,
const std::string &  port 
) [inline, private]

Definition at line 124 of file AlertRelay.h.

Referenced by Initialize().

00125     {
00126         WSADATA wsaData;
00127         SOCKET ListenSocket = INVALID_SOCKET;
00128         struct addrinfo *result = NULL,
00129                         hints;
00130         
00131         // Initialize Winsock
00132         int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
00133         if (iResult != 0) {
00134             printf("WSAStartup failed: %d\n", iResult);
00135             return INVALID_SOCKET;
00136         }
00137 
00138         ZeroMemory(&hints, sizeof(hints));
00139         hints.ai_family = AF_INET;
00140         hints.ai_socktype = SOCK_STREAM;
00141         hints.ai_protocol = IPPROTO_TCP;
00142         hints.ai_flags = AI_PASSIVE;
00143 
00144         // Resolve the server address and port
00145         iResult = getaddrinfo(ipAddress.c_str(), port.c_str(), &hints, &result);
00146         if ( iResult != 0 ) {
00147             printf("getaddrinfo failed: %d\n", iResult);
00148             WSACleanup();
00149             return INVALID_SOCKET;
00150         }
00151         
00152         // Create a SOCKET for connecting to server
00153         ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
00154         if (ListenSocket == INVALID_SOCKET) {
00155             printf("socket failed: %ld\n", WSAGetLastError());
00156             freeaddrinfo(result);
00157             WSACleanup();
00158             return INVALID_SOCKET;
00159         }
00160 
00161         // Setup the TCP listening socket
00162         iResult = bind( ListenSocket, result->ai_addr, (int)result->ai_addrlen);
00163         if (iResult == SOCKET_ERROR) {
00164             printf("bind failed: %d (error 10049: is the server IP address %s valid?)\n", WSAGetLastError(), ipAddress.c_str());
00165             freeaddrinfo(result);
00166             closesocket(ListenSocket);
00167             WSACleanup();
00168             return INVALID_SOCKET;
00169         }
00170 
00171         freeaddrinfo(result);
00172 
00173         iResult = listen(ListenSocket, SOMAXCONN);
00174         if (iResult == SOCKET_ERROR) {
00175             printf("listen failed: %d\n", WSAGetLastError());
00176             closesocket(ListenSocket);
00177             WSACleanup();
00178             return INVALID_SOCKET;
00179         }
00180 
00181         // set to non-blocking mode
00182         u_long argp = 1;
00183         int rc = ioctlsocket(ListenSocket, FIONBIO, &argp); 
00184 
00185         //Sleep(250);
00186             return ListenSocket;
00187     }


Generated on Thu Jan 13 09:15:56 2011 for ImpalaSrc by  doxygen 1.5.1