static void createChannelForAccept(int const acceptedFd, struct sockaddr const peerAddr, TChannel ** const channelPP, void ** const channelInfoPP, const char ** const errorP) { /*---------------------------------------------------------------------------- Make a channel object (TChannel) out of a socket just created by accept() on a listening socket -- i.e. a socket for a client connection. 'acceptedFd' is the file descriptor of the socket. 'peerAddr' is the address of the client, from accept(). -----------------------------------------------------------------------------*/ struct abyss_unix_chaninfo * channelInfoP; makeChannelInfo(&channelInfoP, peerAddr, sizeof(peerAddr), errorP); if (!*errorP) { struct socketUnix * acceptedSocketP; MALLOCVAR(acceptedSocketP); if (!acceptedSocketP) xmlrpc_asprintf(errorP, "Unable to allocate memory"); else { acceptedSocketP->fd = acceptedFd; acceptedSocketP->userSuppliedFd = FALSE; initInterruptPipe(&acceptedSocketP->interruptPipe, errorP); if (!*errorP) { TChannel * channelP; ChannelCreate(&channelVtbl, acceptedSocketP, &channelP); if (!channelP) xmlrpc_asprintf(errorP, "Failed to create TChannel object."); else { *errorP = NULL; *channelPP = channelP; *channelInfoPP = channelInfoP; } if (*errorP) termInterruptPipe(acceptedSocketP->interruptPipe); } if (*errorP) free(acceptedSocketP); } if (*errorP) free(channelInfoP); } }
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); } }
static void makeChannelFromFd(int const fd, TChannel ** const channelPP, const char ** const errorP) { struct socketUnix * socketUnixP; MALLOCVAR(socketUnixP); if (socketUnixP == NULL) xmlrpc_asprintf(errorP, "Unable to allocate memory for Unix " "channel descriptor"); else { TChannel * channelP; socketUnixP->fd = fd; socketUnixP->userSuppliedFd = TRUE; initInterruptPipe(&socketUnixP->interruptPipe, errorP); if (!*errorP) { ChannelCreate(&channelVtbl, socketUnixP, &channelP); if (channelP == NULL) xmlrpc_asprintf(errorP, "Unable to allocate memory for " "channel descriptor."); else { *channelPP = channelP; *errorP = NULL; } if (*errorP) termInterruptPipe(socketUnixP->interruptPipe); } if (*errorP) free(socketUnixP); } }