Exemple #1
0
HttpRequest * EHSConnection::GetNextRequest ( )
{

	HttpRequest * poHttpRequest = NULL;

    if ( MUTEX_TRY_LOCK ( m_oConnectionMutex ) == false )
        return NULL;

	if ( m_oHttpRequestList.empty ( ) ) {

		poHttpRequest = NULL;

	} else {

		poHttpRequest = m_oHttpRequestList.front ( );
		
		m_oHttpRequestList.pop_front ( );
		
	}

	MUTEX_UNLOCK ( m_oConnectionMutex );

	return poHttpRequest;

}
 NetTesterSM(ProxyMutex *_mutex, NetVConnection *_vc) : Continuation(_mutex)
 {
   MUTEX_TRY_LOCK(lock, mutex, _vc->thread);
   ink_release_assert(lock);
   vc = _vc;
   Debug("net_test", "Accepted a connection");
   SET_HANDLER(&NetTesterSM::handle_read);
   req_buf = new_MIOBuffer(1);
   reader = req_buf->alloc_reader();
   read_vio = vc->do_io_read(this, INT64_MAX, req_buf);
   // vc->set_inactivity_timeout(HRTIME_SECONDS(60));
   resp_buf = new_empty_MIOBuffer(6);
   resp_buf->append_block(resp_blk->clone());
   req_len = 0;
   resp_reader = resp_buf->alloc_reader();
 }
Exemple #3
0
int EHSServer::ClearIdleConnections ( )
{

	// don't lock mutex, as it is only called rom within locked sections

	int nIdleConnections = 0;

	for ( EHSConnectionList::iterator i = m_oEHSConnectionList.begin ( );
		  i != m_oEHSConnectionList.end ( );
		  i++ ) {

        if ( MUTEX_TRY_LOCK ( (*i)->m_oConnectionMutex ) == false )
            continue;

		// if it's been more than N seconds since a response has been
		//   sent and there are no pending requests
		if ( (*i)->StillReading ( ) &&
			 ( time ( NULL ) - (*i)->LastActivity ( ) > m_nIdleTimeout || (*i)->m_iStopASAP ) &&
			 !(*i)->RequestsPending ( )
			  ) {

			EHS_TRACE ( "Done reading because of idle timeout\n" );
    
			(*i)->DoneReading ( false );

			nIdleConnections++;

		}
		
		MUTEX_UNLOCK ( (*i)->m_oConnectionMutex );

	}


	if ( nIdleConnections > 0 ) {
		EHS_TRACE ( "Cleared %d connections\n", nIdleConnections );
	}


	RemoveFinishedConnections ( );

	return nIdleConnections;

}
Exemple #4
0
void EHSServer::CheckClientSockets ( )
{
    MUTEX_LOCK ( m_oMutex );

	// go through all the sockets from which we're still reading
	for ( EHSConnectionList::iterator i = m_oEHSConnectionList.begin ( );
		  i != m_oEHSConnectionList.end ( );
		  i++ ) {

		if ( m_oReadFds.IsSet( (*i)->GetNetworkAbstraction()->GetFd(), POLLIN ) ) {

            if ( MUTEX_TRY_LOCK ( (*i)->m_oConnectionMutex ) == false )
                continue;

			EHS_TRACE ( "$$$$$ Got data on client connection\n" );


			// prepare a buffer for the read
			static const int BYTES_TO_READ_AT_A_TIME = 10240;
			char psReadBuffer [ BYTES_TO_READ_AT_A_TIME + 1 ];
			memset ( psReadBuffer, 0, BYTES_TO_READ_AT_A_TIME + 1 );

			// do the actual read
			int nBytesReceived =
				(*i)->GetNetworkAbstraction ( )->Read ( psReadBuffer,
														BYTES_TO_READ_AT_A_TIME );

            if ( nBytesReceived == SOCKET_ERROR )
            {
                int err = GetLastSocketError ();
                if ( err == E_WOULDBLOCK )
                {
                    MUTEX_UNLOCK ( (*i)->m_oConnectionMutex );
                    continue;
                }
            }
			// if we received a disconnect
			if ( nBytesReceived <= 0 ) {

				// we're done reading and we received a disconnect
				(*i)->DoneReading ( true );

			}
			// otherwise we got data
			else {

				// take the data we got and append to the connection's buffer
				EHSConnection::AddBufferResult nAddBufferResult = 
					(*i)->AddBuffer ( psReadBuffer, nBytesReceived );

				// if add buffer failed, don't read from this connection anymore
				if ( nAddBufferResult == EHSConnection::ADDBUFFER_INVALIDREQUEST ||
					 nAddBufferResult == EHSConnection::ADDBUFFER_TOOBIG ) {

					// done reading but did not receieve disconnect
					EHS_TRACE ( "Done reading because we got a bad request\n" );
					(*i)->DoneReading ( false );

				} // end error with AddBuffer

			} // end nBytesReceived

            MUTEX_UNLOCK ( (*i)->m_oConnectionMutex );
		} // FD_ISSET
		
	} // for loop through connections
    MUTEX_UNLOCK ( m_oMutex );

}