File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 1616
1717#include "validate_utf8.h"
1818
19+ #ifndef htobe64
20+ #ifdef __APPLE__
21+ #include <libkern/OSByteOrder.h>
22+ #define htobe64 (h ) OSSwapHostToBigInt64(h)
23+ #elif _MSC_VER
24+ #define htobe64 (h ) _byteswap_uint64(h)
25+ #endif
26+ #endif
27+
1928typedef int8_t ws_state ;
2029#define STATE_ERROR 1
2130#define STATE_READ_HTTP_REQUEST 2
@@ -304,9 +313,18 @@ ws_status ws_send_frame(ws_t self,
304313 * out_tail ++ = ((is_masking ? 0x80 : 0 ) | (!payload_n ? payload_length :
305314 payload_n == 2 ? 126 : 127 ));
306315
307- int8_t j ;
308- for (j = payload_n - 1 ; j >= 0 ; j -- ) {
309- * out_tail ++ = (unsigned char )((payload_length >> (j <<3 )) & 0xFF );
316+ if (payload_n != 0 ) {
317+ if (payload_n == 2 ) {
318+ uint16_t sz16 = htons (payload_length );
319+ memcpy (out_tail , & sz16 , payload_n );
320+ } else {
321+ uint64_t sz64 = htobe64 (payload_length );
322+ memcpy (out_tail , & sz64 , payload_n );
323+ }
324+
325+ int i ;
326+ for (i = 0 ; i < payload_n ; i ++ )
327+ * out_tail ++ ;
310328 }
311329
312330 if (is_masking ) {
You can’t perform that action at this time.
0 commit comments