Ejemplo n.º 1
0
 void CloseAllClients()
 {
     for( int n=0; n<mMaxClientCount; n++ )
     {
         if( mClientEPs[ n ] != NULL )
         {
             InsertCloseRequest( n );
         }
     }
     FlushSendBuffer();
 }
Ejemplo n.º 2
0
 inline void DecreasePendingRequests()
 {
     _bgp_msync();
     mPendingRequests--;
     // if( !mPendingRequests )
     {
         // BegLogLine( 1 )
         //   << "Flushing socket: " << mRouterConnFd
         // //   << " needed: " << NeedsFlush()
         //   << EndLogLine;
         FlushSendBuffer();
     }
 }
	bool TCPNetwork::RunProcessWrite(const int sessionIdx, const SOCKET fd, fd_set& write_set)
	{
		if (FD_ISSET(fd, &write_set) == false)
		{
			return true;
		}

		auto retSend = FlushSendBuffer(sessionIdx);
		if (retSend != NET_ERROR_CODE::NONE)
		{
			CloseSession(SOCKET_CLOSE_CASE::SOCKET_SEND_ERROR, fd, sessionIdx);
			return false;
		}

		return true;
	}
Ejemplo n.º 4
0
    iWARPEM_Status_t InsertMessageVector( const iWARPEM_StreamId_t aClientId,
                                          struct iovec *aIOV,
                                          int aIOV_Count,
                                          int *aLen,
                                          bool aFirstIsHeader = true )
    {
        iWARPEM_Status_t status = IWARPEM_SUCCESS;
        int i=0;
        *aLen = 0;

        // only create the msg header for the first vector
        iWARPEM_Message_Hdr_t *hdr = NULL;
        if( aFirstIsHeader )
        {
            hdr = (iWARPEM_Message_Hdr_t*)aIOV[ 0 ].iov_base;
            *aLen += sizeof( iWARPEM_Message_Hdr_t );
            i++;
        }

        int send_size = aIOV[ i ].iov_len;

        if( GetSendSpace() < send_size )
        {
            status = FlushSendBuffer();
            BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG )
                    << "Remaining space is too small. Sending existing data first.."
                    << " req_size: " << send_size
                    << " rem_space: " << GetSendSpace()
                    << EndLogLine;
        }

        status = InsertMessage( aClientId, hdr, (char*)(aIOV[ i ].iov_base), aIOV[ i ].iov_len, true );
        if( status == IWARPEM_SUCCESS )
            *aLen += send_size;

        pthread_spin_lock( &mAccessLock );
        i++;
        for( ; (i < aIOV_Count ) && ( status == IWARPEM_SUCCESS ); i++ )
        {
            send_size = aIOV[ i ].iov_len;
            StrongAssertLogLine( send_size < GetSendSpace() )
                    << "Message vector entry " << i
                    << " doesn't fit into send buffer. Space: " << GetSendSpace()
                    << " requested: " << send_size
                    << " already inserted: " << *aLen
                    << EndLogLine;

            mSendBuffer->AddDataContigous( (const char*)aIOV[ i ].iov_base, aIOV[ i ].iov_len );
            *aLen += send_size;
        }
        pthread_spin_unlock( &mAccessLock );

        BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG )
                << "Inserted Message Vector to send buffer: "
                << " ClientId: " << aClientId
                << " entries: " << aIOV_Count
                << " msg_size: " << *aLen
                << " bytes in buffer: " << mSendBuffer->GetDataLen()
                << EndLogLine;

        // initiate a send of data once we've filled up the buffer beyond a threshold
        if( mSendBuffer->FlushRecommended() )
            status = FlushSendBuffer();

        return status;
    }
Ejemplo n.º 5
0
    iWARPEM_Status_t InsertMessage( iWARPEM_StreamId_t aClientID,
                                    const iWARPEM_Message_Hdr_t* aHdr,
                                    const char *aData,
                                    int aSize, bool aForceNoFlush = false )
    {
        if( aSize > IT_API_MULTIPLEX_SOCKET_BUFFER_SIZE - sizeof( it_api_multiplexed_socket_message_header_t ) )
        {
            BegLogLine( 1 )
                    << "Requested message size exceeds send buffer size."
                    << " MAX: " << IT_API_MULTIPLEX_SOCKET_BUFFER_SIZE
                    << " actual: " << aSize
                    << EndLogLine;
            return IWARPEM_SUCCESS;
        }
        iWARPEM_Status_t status = IWARPEM_SUCCESS;
        if( GetSendSpace() < aSize )
        {
            AssertLogLine( aForceNoFlush == false )
                    << "Remaining size too small for message but parameters prevent flush."
                    << " remaining=" << GetSendSpace()
                    << " aSize=" << aSize
                    << EndLogLine;

            status = FlushSendBuffer();
            BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG )
                    << "Remaining space is too small. Sending existing data first.."
                    << " req_size: " << aSize
                    << " rem_space: " << GetSendSpace()
                    << EndLogLine;
        }

        pthread_spin_lock( &mAccessLock );
        // create the multiplex header from the client id
        iWARPEM_StreamId_t *client = (iWARPEM_StreamId_t*)&aClientID;
        mSendBuffer->AddHdr( (const char*)client, sizeof( iWARPEM_StreamId_t ) );

        if( aHdr )
            mSendBuffer->AddHdr( (const char*)aHdr, sizeof( iWARPEM_Message_Hdr_t ) );

        if( aSize > 0 )
            mSendBuffer->AddData( aData, aSize );

        pthread_spin_unlock( &mAccessLock );
#if (FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG != 0)
        iWARPEM_Msg_Type_t MsgType = iWARPEM_UNKNOWN_REQ_TYPE;
        if( aHdr )
        {
            MsgType = aHdr->mMsg_Type;
        }

        BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG )
                << "Inserted Message to send buffer: "
                << " ClientId: " << aClientID
                << " msg_size: " << aSize
                << " msg_type: " << iWARPEM_Msg_Type_to_string( MsgType )
                << " bytes in buffer: " << mSendBuffer->GetDataLen()
                << EndLogLine;
#endif

#ifdef MULTIPLEX_STATISTICS
        mMsgCount++;
#endif
        mNeedsBufferFlush = true;

        // initiate a send of data once we've filled up the buffer beyond a threshold
        if( (!aForceNoFlush) && ( mSendBuffer->FlushRecommended() ) )
        {
            BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG )
                    << "Buffer reached threshold fill state. Flushing..."
                    << EndLogLine;
            status = FlushSendBuffer();
        }
        return status;
    }