Ejemplo n.º 1
0
static void
serverFunc(void *const userHandle) {
/*----------------------------------------------------------------------------
   Do server stuff on one connection.  At its simplest, this means do
   one HTTP request.  But with keepalive, it can be many requests.
-----------------------------------------------------------------------------*/
    TConn *const connectionP = userHandle;
    struct _TServer *const srvP = connectionP->server->srvP;

    unsigned int requestCount;
    /* Number of requests we've handled so far on this connection */
    bool connectionDone;
    /* No more need for this HTTP connection */

    requestCount = 0;
    connectionDone = FALSE;

    while (!connectionDone) {
        bool timedOut, eof;
        const char *readError;

        /* Wait for and get beginning (at least ) of next request.  We do
           this separately from getting the rest of the request because we
           treat dead time between requests differently from dead time in
           the middle of a request.
        */
        ConnRead(connectionP, srvP->keepalivetimeout,
                 &timedOut, &eof, &readError);

        if (readError) {
            TraceMsg("Failed to read from Abyss connection.  %s", readError);
            xmlrpc_strfree(readError);
            connectionDone = TRUE;
        } else if (timedOut) {
            connectionDone = TRUE;
        } else if (eof) {
            connectionDone = TRUE;
        } else if (srvP->terminationRequested) {
            connectionDone = TRUE;
        } else {
            bool const lastReqOnConn =
                    requestCount + 1 >= srvP->keepalivemaxconn;

            bool keepalive;

            processRequestFromClient(connectionP, lastReqOnConn, srvP->timeout,
                                     &keepalive);

            ++requestCount;

            if (!keepalive)
                connectionDone = TRUE;

            /**************** Must adjust the read buffer *****************/
            ConnReadInit(connectionP);
        }
    }
}
Ejemplo n.º 2
0
static void
serverFunc(void * const userHandle) {
/*----------------------------------------------------------------------------
   Do server stuff on one connection.  At its simplest, this means do
   one HTTP request.  But with keepalive, it can be many requests.
-----------------------------------------------------------------------------*/
    TConn *           const connectionP = userHandle;
    struct _TServer * const srvP = connectionP->server->srvP;

    unsigned int requestCount;
        /* Number of requests we've handled so far on this connection */
    abyss_bool connectionDone;
        /* No more need for this HTTP connection */

    requestCount = 0;
    connectionDone = FALSE;

    while (!connectionDone) {
        abyss_bool success;
        
        /* Wait to read until timeout */
        success = ConnRead(connectionP, srvP->keepalivetimeout);

        if (!success)
            connectionDone = TRUE;
        else {
            abyss_bool const lastReqOnConn =
                requestCount + 1 >= srvP->keepalivemaxconn;

            abyss_bool keepalive;
            
            processDataFromClient(connectionP, lastReqOnConn, &keepalive);
            
            ++requestCount;

            if (!keepalive)
                connectionDone = TRUE;
            
            /**************** Must adjust the read buffer *****************/
            ConnReadInit(connectionP);
        }
    }
}
Ejemplo n.º 3
0
abyss_bool
SessionRefillBuffer(TSession * const sessionP) {
/*----------------------------------------------------------------------------
   Get the next chunk of data from the connection into the buffer.

   I.e. read data from the socket.
-----------------------------------------------------------------------------*/
    struct _TServer * const srvP = sessionP->conn->server->srvP;
    abyss_bool succeeded;

    /* Reset our read buffer & flush data from previous reads. */
    ConnReadInit(sessionP->conn);

    /* Read more network data into our buffer.  If we encounter a
       timeout, exit immediately.  We're very forgiving about the
       timeout here.  We allow a full timeout per network read, which
       would allow somebody to keep a connection alive nearly
       indefinitely.  But it's hard to do anything intelligent here
       without very complicated code.
    */
    succeeded = ConnRead(sessionP->conn, srvP->timeout);

    return succeeded;
}
Ejemplo n.º 4
0
void ServerFunc(TConn *c)
{
	TRequest r;
	uint32 ka = 0;

	/* sanity */
	if (!c) {
		return;
	}

	ka=c->server->keepalivemaxconn;
	c->pool = ap_make_sub_pool( c->server->pool );
	c->server->stat_conns++;

	RequestInit(&r,c);

	/* tell connection handlers - new connection */
	ap_conn_init_modules( c );

	while (ka--)
	{
		c->start_time = ap_time();

		/* Wait to read until timeout */
		if (!ConnRead(c,c->server->keepalivetimeout)) {
			break;
		}

/* CODE_PROBE_1("Server - Req Read Start (%x)",c); */
		if (RequestRead(&r))
		{
			/* Check if it is the last keepalive */
			if (ka==1) {
				r.keepalive=FALSE;
			}	

			r.cankeepalive=r.keepalive;

			if (r.status==0) {
				if (r.versionmajor>=2) {
					ResponseStatus(&r,505);
				} else if (!RequestValidURI(&r)) {
					ResponseStatus(&r,400);
				} else {
					if( ap_invoke_handler( &r ) == DECLINED ) {
						((HANDLER)(c->server->defaulthandler))(&r);
					}
				}
			}
		}
/* CODE_PROBE_1("Server - Req Read End (%x)",c); */
       		
		HTTPWriteEnd(&r);
		ConnWriteFlush( c );

		if (!r.done)
			ResponseError(&r);

		RequestLog(&r);

		/* do flow stat update */
		c->server->stat_inbytes += c->inbytes;
		c->server->stat_outbytes += c->outbytes;
		c->server->stat_data_time += ap_time() - c->start_time;

                if( c->server->stopped ) {
                        break;
		}
		if (!(r.keepalive && r.cankeepalive)) {
			break;
		}

		RequestReset(&r,c);
		ConnReadInit(c);		
/* CODE_PROBE_1("Server - ConnReadInit - Bottom (%x)",c); */
	}

	/* tell connection handlers session complete */
	ap_conn_exit_modules( c );
	ap_destroy_pool( c->pool );
	RequestFree(&r);

	SocketClose(&(c->socket));
}