Exemplo n.º 1
0
int
crFileRecv( void )
{
	CRMessage *msg;
	int i;

	if (!cr_file.num_conns)
	{
		return 0;
	}
	for ( i = 0; i < cr_file.num_conns; i++ )
	{
		CRFileBuffer *file_buffer;
		unsigned int   len;
		CRConnection  *conn = cr_file.conns[i];

		crFileReadExact( conn, &len, sizeof( len ) );

		CRASSERT( len > 0 );

		if ( len <= conn->buffer_size )
		{
			file_buffer = (CRFileBuffer *) crFileAlloc( conn ) - 1;
		}
		else
		{
			file_buffer = (CRFileBuffer *) 
				crAlloc( sizeof(*file_buffer) + len );
			file_buffer->magic = CR_FILE_BUFFER_MAGIC;
			file_buffer->kind  = CRFileMemoryBig;
			file_buffer->pad   = 0;
		}

		file_buffer->len = len;

		crFileReadExact( conn, file_buffer + 1, len );

		conn->recv_credits -= len;

		msg = (CRMessage *) (file_buffer + 1);
		crNetDispatchMessage( cr_file.recv_list, conn, msg, len );

		/* CR_MESSAGE_OPCODES is freed in
		 * crserverlib/server_stream.c 
		 *
		 * OOB messages are the programmer's problem.  -- Humper 12/17/01 */
		if (msg->header.type != CR_MESSAGE_OPCODES && msg->header.type != CR_MESSAGE_OOB)
		{
			crFileFree( conn, file_buffer + 1 );
		}
	}

	return 1;
}
Exemplo n.º 2
0
static void
crSDPHandleNewMessage( CRConnection *conn, CRMessage *msg,
                       unsigned int len )
{
	CRSDPBuffer *buf = ((CRSDPBuffer *) msg) - 1;
  
	/* build a header so we can delete the message later */
	buf->magic = CR_SDP_BUFFER_MAGIC;
	buf->kind  = CRSDPMemory;
	buf->len   = len;
	buf->pad   = 0;
  
	crNetDispatchMessage( cr_sdp.recv_list, conn, msg, len );
}
Exemplo n.º 3
0
static void _crVBoxHGSMIReceiveMessage(CRConnection *conn, PCRVBOXHGSMI_CLIENT pClient)
{
    uint32_t len;
    CRVBOXHGSMIBUFFER* pSysBuf;
    CRMessage *msg;
    CRMessageType cached_type;

    len = conn->cbBuffer;
    Assert(len > 0);
    Assert(conn->pBuffer);
    CRASSERT(len > 0);
    CRASSERT(conn->pBuffer);

#ifndef IN_GUEST
    if (conn->allow_redir_ptr)
    {
#endif //IN_GUEST
        CRASSERT(conn->buffer_size >= sizeof(CRMessageRedirPtr));

        pSysBuf = _crVBoxHGSMISysMemAlloc( conn->buffer_size );
        pSysBuf->u32Len = sizeof(CRMessageRedirPtr);

        msg = (CRMessage *)CRVBOXHGSMI_BUF_DATA(pSysBuf);

        msg->header.type = CR_MESSAGE_REDIR_PTR;
        msg->redirptr.pMessage = (CRMessageHeader*) (conn->pBuffer);
        msg->header.conn_id = msg->redirptr.pMessage->conn_id;

        cached_type = msg->redirptr.pMessage->type;

        conn->cbBuffer = 0;
        conn->pBuffer  = NULL;
#ifndef IN_GUEST
    }
    else
    {
        if ( len <= conn->buffer_size )
        {
            /* put in pre-allocated buffer */
            hgcm_buffer = (CRVBOXHGCMBUFFER *) crVBoxHGCMAlloc( conn ) - 1;
        }
        else
        {
            /* allocate new buffer,
             * not using pool here as it's most likely one time transfer of huge texture
             */
            hgcm_buffer            = (CRVBOXHGCMBUFFER *) crAlloc( sizeof(CRVBOXHGCMBUFFER) + len );
            hgcm_buffer->magic     = CR_VBOXHGCM_BUFFER_MAGIC;
            hgcm_buffer->kind      = CR_VBOXHGCM_MEMORY_BIG;
            hgcm_buffer->allocated = sizeof(CRVBOXHGCMBUFFER) + len;
# ifdef RT_OS_WINDOWS
            hgcm_buffer->pDDS      = NULL;
# endif
        }

        hgcm_buffer->len = len;

        _crVBoxHGCMReadBytes(conn, hgcm_buffer + 1, len);

        msg = (CRMessage *) (hgcm_buffer + 1);
        cached_type = msg->header.type;
    }
#endif //IN_GUEST

    conn->recv_credits     -= len;
    conn->total_bytes_recv += len;
    conn->recv_count++;

    crNetDispatchMessage( g_crvboxhgsmi.recv_list, conn, msg, len );

    /* CR_MESSAGE_OPCODES is freed in crserverlib/server_stream.c with crNetFree.
     * OOB messages are the programmer's problem.  -- Humper 12/17/01
     */
    if (cached_type != CR_MESSAGE_OPCODES
        && cached_type != CR_MESSAGE_OOB
        && cached_type != CR_MESSAGE_GATHER)
    {
        _crVBoxHGSMIFree(conn, msg);
    }
}
Exemplo n.º 4
0
/**
 * Receive the next message on the given connection.
 * If we're being called by crSDPRecv(), we already know there's
 * something to receive.
 */
static void
crSDPReceiveMessage(CRConnection *conn)
{
	CRMessage *msg;
	CRMessageType cached_type;
	CRSDPBuffer *sdp_buffer;
	unsigned int len, total, leftover;
	const CRSocket sock = conn->sdp_socket;

	/* this reads the length of the message */
	if ( __sdp_read_exact( sock, &len, sizeof(len)) <= 0 )
	{
		__sdp_dead_connection( conn );
		return;
	}

	if (conn->swap)
		len = SWAP32(len);

	CRASSERT( len > 0 );

	if ( len <= conn->buffer_size )
	{
		sdp_buffer = (CRSDPBuffer *) crSDPAlloc( conn ) - 1;
		CRASSERT(sdp_buffer->magic == CR_SDP_BUFFER_MAGIC);
		CRASSERT(sdp_buffer->allocated > 0);
	}
	else
	{
		crWarning("Sending as BIG, the performance is going to tank!!!.  You need larger buffers!!!");
		sdp_buffer = (CRSDPBuffer *) crAlloc( sizeof(*sdp_buffer) + len );
		sdp_buffer->magic = CR_SDP_BUFFER_MAGIC;
		sdp_buffer->kind  = CRSDPMemoryBig;
		sdp_buffer->pad   = 0;
	}

	sdp_buffer->len = len;

	/* if we have set a userbuf, and there is room in it, we probably 
	 * want to stick the message into that, instead of our allocated
	 * buffer.  */
	leftover = 0;
	total = len;
	if ((conn->userbuf != NULL) && (conn->userbuf_len >= (int) sizeof(CRMessageHeader)))
	{
		leftover = len - sizeof(CRMessageHeader);
		total = sizeof(CRMessageHeader);
	}
	if ( __sdp_read_exact( sock, sdp_buffer + 1, total) <= 0 )
	{
		crWarning( "Bad juju: %d %d on sock %x", sdp_buffer->allocated, total, sock );
		crFree( sdp_buffer );
		__sdp_dead_connection( conn );
		return;
	}

	conn->recv_credits -= total;
	conn->total_bytes_recv +=  total;
    
	msg = (CRMessage *) (sdp_buffer + 1);
	cached_type = msg->header.type;
	if (conn->swap)
	{
		msg->header.type = (CRMessageType) SWAP32( msg->header.type );
		msg->header.conn_id = (CRMessageType) SWAP32( msg->header.conn_id );
	}
    
	/* if there is still data pending, it should go into the user buffer */
	if (leftover)
	{
		unsigned int handled = crSDPUserbufRecv(conn, msg);
      
		/* if there is anything left, plop it into the recv_buffer */
		if (leftover - handled)
		{
			if ( __sdp_read_exact( sock, sdp_buffer + 1 + total, leftover-handled) <= 0 )
			{
				crWarning( "Bad juju: %d %d", sdp_buffer->allocated, leftover-handled);
				crFree( sdp_buffer );
				__sdp_dead_connection( conn );
				return;
			}
		}

		conn->recv_credits -= handled;
		conn->total_bytes_recv +=  handled;
	}

	crNetDispatchMessage( cr_sdp.recv_list, conn, msg, len );

	/* CR_MESSAGE_OPCODES is freed in crserverlib/server_stream.c with crNetFree.
	 * OOB messages are the programmer's problem.  -- Humper 12/17/01
	 */
	if (cached_type != CR_MESSAGE_OPCODES && cached_type != CR_MESSAGE_OOB
			&&	cached_type != CR_MESSAGE_GATHER) 
	{
		crSDPFree( conn, sdp_buffer + 1 );
	}
}