void crFileConnection( CRConnection *conn ) { int n_bytes; CRASSERT( cr_file.initialized ); conn->type = CR_FILE; conn->Alloc = crFileAlloc; conn->Send = crFileSend; conn->SendExact = crFileWriteExact; conn->Recv = crFileSingleRecv; conn->Free = crFileFree; conn->Accept = crFileAccept; conn->Connect = crFileDoConnect; conn->Disconnect = crFileDoDisconnect; conn->InstantReclaim = crFileInstantReclaim; conn->HandleNewMessage = crFileHandleNewMessage; conn->index = cr_file.num_conns; conn->sizeof_buffer_header = sizeof( CRFileBuffer ); conn->actual_network = 0; conn->filename = crStrdup( conn->hostname ); n_bytes = ( cr_file.num_conns + 1 ) * sizeof(*cr_file.conns); crRealloc( (void **) &cr_file.conns, n_bytes ); cr_file.conns[cr_file.num_conns++] = conn; }
void crVBoxHGSMIConnection(CRConnection *conn) { int i, found = 0; int n_bytes; CRASSERT(g_crvboxhgsmi.initialized); conn->type = CR_VBOXHGCM; conn->Alloc = crVBoxHGSMIAlloc; conn->Send = crVBoxHGSMISend; conn->SendExact = crVBoxHGSMIWriteExact; conn->Recv = crVBoxHGSMISingleRecv; conn->RecvMsg = crVBoxHGSMIReceiveMessage; conn->Free = crVBoxHGSMIFree; conn->Accept = crVBoxHGSMIAccept; conn->Connect = crVBoxHGSMIDoConnect; conn->Disconnect = crVBoxHGSMIDoDisconnect; conn->InstantReclaim = crVBoxHGSMIInstantReclaim; conn->HandleNewMessage = crVBoxHGSMIHandleNewMessage; conn->index = g_crvboxhgsmi.num_conns; conn->sizeof_buffer_header = sizeof(CRVBOXHGSMIBUFFER); conn->actual_network = 1; conn->krecv_buf_size = 0; conn->pBuffer = NULL; conn->cbBuffer = 0; conn->allow_redir_ptr = 1; //@todo remove this crap at all later conn->cbHostBufferAllocated = 0;//2*1024; conn->pHostBuffer = NULL;//(uint8_t*) crAlloc(conn->cbHostBufferAllocated); // CRASSERT(conn->pHostBuffer); conn->cbHostBuffer = 0; /* Find a free slot */ for (i = 0; i < g_crvboxhgsmi.num_conns; i++) { if (g_crvboxhgsmi.conns[i] == NULL) { conn->index = i; g_crvboxhgsmi.conns[i] = conn; found = 1; break; } } /* Realloc connection stack if we couldn't find a free slot */ if (found == 0) { n_bytes = ( g_crvboxhgsmi.num_conns + 1 ) * sizeof(*g_crvboxhgsmi.conns); crRealloc( (void **) &g_crvboxhgsmi.conns, n_bytes ); g_crvboxhgsmi.conns[g_crvboxhgsmi.num_conns++] = conn; } }
/** * Receive a chunk of a CR_MESSAGE_MULTI_BODY/TAIL transmission. * \param conn the network connection * \param msg the incoming multi-part message * \param len number of bytes in the message */ static void crNetRecvMulti( CRConnection *conn, CRMessageMulti *msg, unsigned int len ) { CRMultiBuffer *multi = &(conn->multi); unsigned char *src, *dst; CRASSERT( len > sizeof(*msg) ); len -= sizeof(*msg); /* Check if there's enough room in the multi-buffer to append 'len' bytes */ if ( len + multi->len > multi->max ) { if ( multi->max == 0 ) { multi->len = conn->sizeof_buffer_header; multi->max = 8192; /* arbitrary initial size */ } /* grow the buffer by 2x until it's big enough */ while ( len + multi->len > multi->max ) { multi->max <<= 1; } crRealloc( &multi->buf, multi->max ); } dst = (unsigned char *) multi->buf + multi->len; src = (unsigned char *) msg + sizeof(*msg); crMemcpy( dst, src, len ); multi->len += len; if (msg->header.type == CR_MESSAGE_MULTI_TAIL) { /* OK, we've collected the last chunk of the multi-part message */ conn->HandleNewMessage( conn, (CRMessage *) (((char *) multi->buf) + conn->sizeof_buffer_header), multi->len - conn->sizeof_buffer_header ); /* clean this up before calling the user */ multi->buf = NULL; multi->len = 0; multi->max = 0; } /* Don't do this too early! */ conn->InstantReclaim( conn, (CRMessage *) msg ); }
void crSDPConnection( CRConnection *conn ) { int i, found = 0; int n_bytes; CRASSERT( cr_sdp.initialized ); conn->type = CR_SDP; conn->Alloc = crSDPAlloc; conn->Send = crSDPSend; conn->SendExact = crSDPWriteExact; conn->Recv = crSDPSingleRecv; conn->RecvMsg = crSDPReceiveMessage; conn->Free = crSDPFree; conn->Accept = crSDPAccept; conn->Connect = crSDPDoConnect; conn->Disconnect = crSDPDoDisconnect; conn->InstantReclaim = crSDPInstantReclaim; conn->HandleNewMessage = crSDPHandleNewMessage; conn->index = cr_sdp.num_conns; conn->sizeof_buffer_header = sizeof( CRSDPBuffer ); conn->actual_network = 1; conn->krecv_buf_size = 0; /* Find a free slot */ for (i = 0; i < cr_sdp.num_conns; i++) { if (cr_sdp.conns[i] == NULL) { conn->index = i; cr_sdp.conns[i] = conn; found = 1; break; } } /* Realloc connection stack if we couldn't find a free slot */ if (found == 0) { n_bytes = ( cr_sdp.num_conns + 1 ) * sizeof(*cr_sdp.conns); crRealloc( (void **) &cr_sdp.conns, n_bytes ); cr_sdp.conns[cr_sdp.num_conns++] = conn; } }