int FileRepConnServer_StartListener( char *hostAddress, int portLocal) { int status = STATUS_OK; int i; for (i=0; i < FILEREP_MAX_LISTEN; i++) { listenSocket[i] = -1; } /* NOTE check if family AF_UNIX has to be considered as well */ status = StreamServerPort( AF_UNSPEC, hostAddress, (unsigned short) portLocal, NULL, listenSocket, FILEREP_MAX_LISTEN); if (status != STATUS_OK) { ereport(WARNING, (errcode_for_socket_access(), errmsg("could not start listener, host:'%s' port:'%d': %m", hostAddress, portLocal), errSendAlert(true), FileRep_errcontext())); } return status; }
int initializeSocketServer_RMSEG(void) { int res = FUNC_RETURN_OK; int netres = 0; char *allip = "0.0.0.0"; pgsocket RMListenSocket[HAWQRM_SERVER_PORT_COUNT]; for ( int i = 0 ; i < HAWQRM_SERVER_PORT_COUNT ; ++i ) { RMListenSocket[i] = PGINVALID_SOCKET; } /* Listen normal socket addresses. */ netres = StreamServerPort( AF_UNSPEC, allip, rm_segment_port, NULL, RMListenSocket, HAWQRM_SERVER_PORT_COUNT); /* If there are multiple segments in one host, which is common in old imp. * We can not make all segments work. So, if HAWQ RM SEG fails to start * socket server by listening the port, we accept this case and make it * silent. HAWQ RM will not recognize this segment and will not assign * tasks. */ if ( netres != STATUS_OK ) { res = REQUESTHANDLER_FAIL_START_SOCKET_SERVER; elog( LOG, "Can not create socket server. HostName=%s, Port=%d", allip, rm_segment_port); return res; } /* Initialize array for polling all file descriptors. */ initializeAsyncComm(); int validfdcount = 0; AsyncCommBuffer newbuffer = NULL; for ( int i = 0 ; i < HAWQRM_SERVER_PORT_COUNT ; ++i ) { if (RMListenSocket[i] != PGINVALID_SOCKET) { netres = registerFileDesc(RMListenSocket[i], NULL, ASYNCCOMM_READ, &AsyncCommBufferHandlersMsgServer, NULL, &newbuffer); if ( netres != FUNC_RETURN_OK ) { res = REQUESTHANDLER_FAIL_START_SOCKET_SERVER; elog(LOG, "Resource manager cannot track socket server."); break; } validfdcount++; InitHandler_Message(newbuffer); } } if ( res != FUNC_RETURN_OK ) { for ( int i = 0 ; i < HAWQRM_SERVER_PORT_COUNT ; ++i ) { if ( RMListenSocket[i] != PGINVALID_SOCKET ) close(RMListenSocket[i]); } return res; } elog(DEBUG5, "HAWQ RM SEG :: Starts accepting resource request. " "Listening normal socket port %s:%d. " "Total listened %d FDs.", allip, rm_segment_port, validfdcount); return res; }