/* *---------------------------------------------------------------------- * * FCGX_CreateWriter -- * * Creates a stream to write streamType FastCGI records, using * the given ipcFd and request Id. This function is provided * for use by cgi-fcgi. In order to be defensive against misuse, * this function leaks a little storage; cgi-fcgi doesn't care. * *---------------------------------------------------------------------- */ FCGX_Stream *FCGX_CreateWriter(int ipcFd, int requestId, int bufflen, int streamType) { FCGX_Request *reqDataPtr = (FCGX_Request *) Malloc(sizeof(FCGX_Request)); reqDataPtr->ipcFd = ipcFd; reqDataPtr->requestId = requestId; /* * Suppress writing an FCGI_END_REQUEST record. */ reqDataPtr->nWriters = 2; return NewWriter(reqDataPtr, bufflen, streamType); }
static bool _WorkerInit(ThreadData _worker) { Worker* worker = (Worker*)_worker; if ((worker->queue = NewQueue()) == NULL) { return false; } if ((worker->pool = NewBufferPool(worker->bufferSize)) == NULL) { return false; } if ((worker->writer = NewWriter(worker->pipe, worker->bufferSize)) == NULL) { return false; } Log(AIO4C_LOG_LEVEL_DEBUG, "initialized with tid 0x%08lx", ThreadGetId(worker->thread)); return true; }
/* *---------------------------------------------------------------------- * * FCGX_Accept_r -- * * Accepts a new request from the HTTP server. * * Results: * 0 for successful call, -1 for error. * * Side effects: * * Finishes the request accepted by (and frees any * storage allocated by) the previous call to FCGX_Accept. * Creates input, output, and error streams and * assigns them to *in, *out, and *err respectively. * Creates a parameters data structure to be accessed * via getenv(3) (if assigned to environ) or by FCGX_GetParam * and assigns it to *envp. * * DO NOT retain pointers to the envp array or any strings * contained in it (e.g. to the result of calling FCGX_GetParam), * since these will be freed by the next call to FCGX_Finish * or FCGX_Accept. * *---------------------------------------------------------------------- */ int FCGX_Accept_r(FCGX_Request * reqDataPtr) { if (!libInitialized) { return -9998; } /* Finish the current request, if any. */ FCGX_Finish_r(reqDataPtr); for (;;) { /* * If a connection isn't open, accept a new connection (blocking). * If an OS error occurs in accepting the connection, * return -1 to the caller, who should exit. */ if (reqDataPtr->ipcFd < 0) { int fail_on_intr = reqDataPtr->flags & FCGI_FAIL_ACCEPT_ON_INTR; reqDataPtr->ipcFd = OS_Accept(reqDataPtr->listen_sock, fail_on_intr, webServerAddressList); if (reqDataPtr->ipcFd < 0) { return (errno > 0) ? (0 - errno) : -9999; } } /* * A connection is open. Read from the connection in order to * get the request's role and environment. If protocol or other * errors occur, close the connection and try again. */ reqDataPtr->isBeginProcessed = FALSE; reqDataPtr->in = NewReader(reqDataPtr, 8192, 0); FillBuffProc(reqDataPtr->in); if (!reqDataPtr->isBeginProcessed) { goto TryAgain; } { char *roleStr; switch (reqDataPtr->role) { case FCGI_RESPONDER: roleStr = "FCGI_ROLE=RESPONDER"; break; case FCGI_AUTHORIZER: roleStr = "FCGI_ROLE=AUTHORIZER"; break; case FCGI_FILTER: roleStr = "FCGI_ROLE=FILTER"; break; default: goto TryAgain; } reqDataPtr->paramsPtr = NewParams(30); PutParam(reqDataPtr->paramsPtr, StringCopy(roleStr)); } SetReaderType(reqDataPtr->in, FCGI_PARAMS); if (ReadParams(reqDataPtr->paramsPtr, reqDataPtr->in) >= 0) { /* * Finished reading the environment. No errors occurred, so * leave the connection-retry loop. */ break; } /* * Close the connection and try again. */ TryAgain: FCGX_Free(reqDataPtr, 1); } /* for (;;) */ /* * Build the remaining data structures representing the new * request and return successfully to the caller. */ SetReaderType(reqDataPtr->in, FCGI_STDIN); reqDataPtr->out = NewWriter(reqDataPtr, 8192, FCGI_STDOUT); reqDataPtr->err = NewWriter(reqDataPtr, 512, FCGI_STDERR); reqDataPtr->nWriters = 2; reqDataPtr->envp = reqDataPtr->paramsPtr->vec; return 0; }
static void WriteCmd ( struct AHIRequest *ioreq, struct AHIBase *AHIBase ) { struct AHIDevUnit *iounit; ULONG error = 0; if(AHIBase->ahib_DebugLevel >= AHI_DEBUG_HIGH) { KPrintF("CMD_WRITE\n"); } iounit = (struct AHIDevUnit *) ioreq->ahir_Std.io_Unit; /* Start playback if neccessary */ if( ! iounit->IsPlaying) { if( (! iounit->FullDuplex) && iounit->IsRecording) { error = AHIE_HALFDUPLEX; // FIXIT! } else { error = AHI_ControlAudio(iounit->AudioCtrl, AHIC_Play,TRUE, TAG_DONE); } if( ! error) { iounit->IsPlaying = TRUE; } } ioreq->ahir_Extras = (ULONG) AllocVec(sizeof(struct Extras), MEMF_PUBLIC|MEMF_CLEAR); if(ioreq->ahir_Extras == NULL) { error = AHIE_NOMEM; } else { // Initialize the structure GetExtras(ioreq)->Channel = NOCHANNEL; GetExtras(ioreq)->Sound = AHI_NOSOUND; GetExtras(ioreq)->Count = 2; } if(iounit->IsPlaying && !error) { ioreq->ahir_Std.io_Actual = 0; // Convert length in bytes to length in samples ioreq->ahir_Std.io_Length /= AHI_SampleFrameSize(ioreq->ahir_Type); switch(ioreq->ahir_Type) { case AHIST_M8S: case AHIST_S8S: case AHIST_M16S: case AHIST_S16S: break; case AHIST_M32S: case AHIST_S32S: default: error = AHIE_BADSAMPLETYPE; } if(! error) { NewWriter(ioreq, iounit, AHIBase); } } if(error) { ioreq->ahir_Std.io_Error = error; TermIO(ioreq, AHIBase); } }