void ChanSwitchUnixCreate(unsigned short const portNumber, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { /*---------------------------------------------------------------------------- Create a POSIX-socket-based channel switch. Use an IP socket. Set the socket's local address so that a subsequent "listen" will listen on all IP addresses, port number 'portNumber'. -----------------------------------------------------------------------------*/ int rc; rc = socket(AF_INET, SOCK_STREAM, 0); if (rc < 0) xmlrpc_asprintf(errorP, "socket() failed with errno %d (%s)", errno, strerror(errno)); else { int const socketFd = rc; setSocketOptions(socketFd, errorP); if (!*errorP) { bindSocketToPort(socketFd, NULL, portNumber, errorP); if (!*errorP) { bool const userSupplied = false; createChanSwitch(socketFd, userSupplied, chanSwitchPP, errorP); } } if (*errorP) close(socketFd); } }
void ChanSwitchUnixCreate2(int const protocolFamily, const struct sockaddr * const sockAddrP, socklen_t const sockAddrLen, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { int rc; rc = socket(protocolFamily, SOCK_STREAM, 0); if (rc < 0) xmlrpc_asprintf(errorP, "socket() failed with errno %d (%s)", errno, strerror(errno)); else { int const socketFd = rc; if (SwitchTraceIsActive) fprintf(stderr, "Created socket for protocol family %d\n", protocolFamily); setSocketOptions(socketFd, errorP); if (!*errorP) { bindSocketToPort(socketFd, sockAddrP, sockAddrLen, errorP); if (!*errorP) { bool const userSupplied = false; createChanSwitch(socketFd, userSupplied, chanSwitchPP, errorP); } } if (*errorP) close(socketFd); } }
void ChanSwitchWinCreate(uint16_t const portNumber, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { /*---------------------------------------------------------------------------- Create a Winsock-based channel switch. Set the socket's local address so that a subsequent "listen" will listen on all IP addresses, port number 'portNumber'. -----------------------------------------------------------------------------*/ struct socketWin * socketWinP; MALLOCVAR(socketWinP); if (!socketWinP) xmlrpc_asprintf(errorP, "Unable to allocate memory for Windows socket " "descriptor structure."); else { SOCKET winsock; winsock = socket(AF_INET, SOCK_STREAM, 0); if (winsock == 0 || winsock == INVALID_SOCKET) { int const lastError = WSAGetLastError(); xmlrpc_asprintf(errorP, "socket() failed with WSAERROR %d (%s)", lastError, getWSAError(lastError)); } else { socketWinP->winsock = winsock; socketWinP->userSuppliedWinsock = FALSE; socketWinP->interruptEvent = CreateEvent(NULL, FALSE, FALSE, NULL); setSocketOptions(socketWinP->winsock, errorP); if (!*errorP) { bindSocketToPort(socketWinP->winsock, NULL, portNumber, errorP); if (!*errorP) ChanSwitchCreate(&chanSwitchVtbl, socketWinP, chanSwitchPP); } if (*errorP) { CloseHandle(socketWinP->interruptEvent); closesocket(winsock); } } if (*errorP) free(socketWinP); } }
bool DatagramSocket::bindToPort (const int port) { return bindSocketToPort (handle, port); }
//============================================================================== bool StreamingSocket::bindToPort (const int port) { return bindSocketToPort (handle, port); }