void ChanSwitchWinCreateWinsock(SOCKET const winsock, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { struct socketWin * socketWinP; if (connected(winsock)) xmlrpc_asprintf(errorP, "Socket is in connected state."); else { MALLOCVAR(socketWinP); if (socketWinP == NULL) xmlrpc_asprintf(errorP, "unable to allocate memory for Windows " "socket descriptor."); else { TChanSwitch * chanSwitchP; socketWinP->winsock = winsock; socketWinP->userSuppliedWinsock = TRUE; ChanSwitchCreate(&chanSwitchVtbl, socketWinP, &chanSwitchP); if (chanSwitchP == NULL) xmlrpc_asprintf(errorP, "Unable to allocate memory for " "channel switch descriptor"); else { *chanSwitchPP = chanSwitchP; *errorP = NULL; } if (*errorP) free(socketWinP); } } }
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); } }
void ChanSwitchWinCreate2(int const protocolFamily, const struct sockaddr * const sockAddrP, socklen_t const sockAddrLen, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { struct socketWin * socketWinP; MALLOCVAR(socketWinP); if (!socketWinP) xmlrpc_asprintf(errorP, "Unable to allocate memory for Windows socket " "descriptor structure."); else { SOCKET winsock; winsock = socket(protocolFamily, 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) { bindSocketToAddr(socketWinP->winsock, sockAddrP, sockAddrLen, errorP); if (!*errorP) ChanSwitchCreate(&chanSwitchVtbl, socketWinP, chanSwitchPP); } if (*errorP) { CloseHandle(socketWinP->interruptEvent); closesocket(winsock); } } if (*errorP) free(socketWinP); } }
static void createChanSwitch(int const fd, bool const userSuppliedFd, TChanSwitch ** const chanSwitchPP, const char ** const errorP) { struct socketUnix * socketUnixP; assert(!connected(fd)); if (SwitchTraceIsActive) fprintf(stderr, "Creating Unix listen-socket based channel switch\n"); MALLOCVAR(socketUnixP); if (socketUnixP == NULL) xmlrpc_asprintf(errorP, "unable to allocate memory for Unix " "channel switch descriptor."); else { TChanSwitch * chanSwitchP; socketUnixP->fd = fd; socketUnixP->userSuppliedFd = userSuppliedFd; initInterruptPipe(&socketUnixP->interruptPipe, errorP); if (!*errorP) { ChanSwitchCreate(&chanSwitchVtbl, socketUnixP, &chanSwitchP); if (*errorP) termInterruptPipe(socketUnixP->interruptPipe); if (chanSwitchP == NULL) xmlrpc_asprintf(errorP, "Unable to allocate memory for " "channel switch descriptor"); else { *chanSwitchPP = chanSwitchP; *errorP = NULL; } } if (*errorP) free(socketUnixP); } }