MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / internal_write_socket

Function internal_write_socket

src/humblenet/src/libsocket.cpp:469–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467}
468
469int internal_write_socket(internal_socket_t* socket, const void *buf, int bufsize) {
470 if( socket->wsi ) {
471 // TODO: Should this buffer the data like the docuemntation states and only write on the writable callback ?
472
473#if LWS_SEND_BUFFER_PRE_PADDING == 0 && LWS_SEND_BUFFER_POST_PADDING == 0
474 int retval = libwebsocket_write(socket->wsi, buf, bufsize, LWS_WRITE_BINARY);
475#else
476 // libwebsocket requires the caller to allocate the frame prefix/suffix storage.
477 std::vector<unsigned char> sendbuf(LWS_SEND_BUFFER_PRE_PADDING + bufsize + LWS_SEND_BUFFER_POST_PADDING, 0);
478 memcpy(&sendbuf[LWS_SEND_BUFFER_PRE_PADDING], buf, bufsize);
479
480 int retval = libwebsocket_write(socket->wsi, &sendbuf[LWS_SEND_BUFFER_PRE_PADDING], bufsize, LWS_WRITE_BINARY);
481#endif
482
483 // mark it non-writable and tell websocket to inform us when it's writable again
484 //connection->writable = false;
485 if( retval > 0 ) {
486 libwebsocket_callback_on_writable(g_context->websocket, socket->wsi);
487 }
488
489 return retval;
490
491 } else if( socket->webrtc && socket->webrtc_channel ) {
492 return libwebrtc_write( socket->webrtc_channel, buf, bufsize );
493 }
494
495 // bad/disconnected socket
496 return -1;
497}
498

Callers 4

sendP2PMessageFunction · 0.85
on_writableFunction · 0.85
run_message_testFunction · 0.85

Calls 3

libwebsocket_writeFunction · 0.70
libwebrtc_writeFunction · 0.70

Tested by 1

run_message_testFunction · 0.68