library/src/network/httpd/BP-HTTPdWebSocketRequestHandlers.cc
// Send text data over a websocket.  Text data will be
// marked with a text opocode set within the frame/header when sent.
Send text data over a websocket.  Text data will be
marked with a text opocode set within the frame/header when sent.
Send text data over a websocket . Text data will be marked with a text opocode set within the frame / header when sent .
BP_ERROR_T BP_HTTPdWebsocketSend
(
	P_BP_HTTPD_WEBSOCKET            websocket,
	BP_HTTPD_WEBSOCKET_FRAME_OPCODE opcode,
	char                           *send_data,
	size_t                          send_data_size,
	size_t                          send_chunk_max_size,
	int                             additional_tcp_flags,
	BP_BOOL                         perform_masking_before_send
)
{
	if(!websocket)
		return ERR_FAILURE;
	if(!opcode)
		return ERR_FAILURE;
	if(!send_data)
		return ERR_FAILURE;
	if(!send_data_size)
		return ERR_FAILURE;
	if(!send_chunk_max_size)
		return ERR_FAILURE;
	BP_HTTPD_WEBSOCKET_ENCODED_SEND_FRAME_HEADER header_to_send;
	BP_ZERO_STACK(header_to_send);
	header_to_send.fin_flag   = BP_TRUE;
	header_to_send.opcode    = opcode;
	if(perform_masking_before_send == BP_TRUE)
	{
		header_to_send.mask_flag = BP_TRUE;
		header_to_send.masking_key[0] = BP_GenerateRandomUChar(0x00, 0xff);
		header_to_send.masking_key[1] = BP_GenerateRandomUChar(0x00, 0xff);
		header_to_send.masking_key[2] = BP_GenerateRandomUChar(0x00, 0xff);
		header_to_send.masking_key[3] = BP_GenerateRandomUChar(0x00, 0xff);
	}
	header_to_send.payload_len = (uint64_t) send_data_size;
	BP_HTTPdWebsocketEncodeSendFrameHeader(	&header_to_send	);
	BP_HTTPdWebsocketSendRaw
	(
		websocket,
		&header_to_send,
		(unsigned char *) send_data,
		send_data_size,
		send_chunk_max_size,
		additional_tcp_flags
	);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdWebsocketSend ( P_BP_HTTPD_WEBSOCKET websocket , BP_HTTPD_WEBSOCKET_FRAME_OPCODE opcode , char * send_data , size_t send_data_size , size_t send_chunk_max_size , int additional_tcp_flags , BP_BOOL perform_masking_before_send ) { if ( ! websocket ) return ERR_FAILURE ; if ( ! opcode ) return ERR_FAILURE ; if ( ! send_data ) return ERR_FAILURE ; if ( ! send_data_size ) return ERR_FAILURE ; if ( ! send_chunk_max_size ) return ERR_FAILURE ; BP_HTTPD_WEBSOCKET_ENCODED_SEND_FRAME_HEADER header_to_send ; BP_ZERO_STACK ( header_to_send ) ; header_to_send . fin_flag = BP_TRUE ; header_to_send . opcode = opcode ; if ( perform_masking_before_send == BP_TRUE ) { header_to_send . mask_flag = BP_TRUE ; header_to_send . masking_key [ 0 ] = BP_GenerateRandomUChar ( 0x00 , 0xff ) ; header_to_send . masking_key [ 1 ] = BP_GenerateRandomUChar ( 0x00 , 0xff ) ; header_to_send . masking_key [ 2 ] = BP_GenerateRandomUChar ( 0x00 , 0xff ) ; header_to_send . masking_key [ 3 ] = BP_GenerateRandomUChar ( 0x00 , 0xff ) ; } header_to_send . payload_len = ( uint64_t ) send_data_size ; BP_HTTPdWebsocketEncodeSendFrameHeader ( & header_to_send ) ; BP_HTTPdWebsocketSendRaw ( websocket , & header_to_send , ( unsigned char * ) send_data , send_data_size , send_chunk_max_size , additional_tcp_flags ) ; return ERR_SUCCESS ; }
Send text data over a websocket.
Send text data over a websocket .
// run basic checks // --- encode send frame ----- // create a raw header to send // set fin flag // set opcode // set mask flag and masking key if necessary // ensure mask flag is enabled // create random masking key // set the payload length // encode the send frame header // attempt to send encoded data // return indicating success