|
@@ -41,8 +41,15 @@ void IZ_AppHandleNetworkingOutboundEvents(IZ_App* app) { |
|
|
lws_get_protocol(wsi) |
|
|
lws_get_protocol(wsi) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
IZ_WebsocketMessage* amsg = IZ_WSClientCreateMessage(wsi, false, "hello", 5); |
|
|
|
|
|
lws_ring_insert(vhd->ring, amsg, 1); |
|
|
|
|
|
|
|
|
IZ_WebsocketMessage amsg; |
|
|
|
|
|
i32 result; |
|
|
|
|
|
result = IZ_WebsocketCreateTextMessage(wsi, &amsg, "hello", 5); |
|
|
|
|
|
|
|
|
|
|
|
if (result < 0) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lws_ring_insert(vhd->ring, &amsg, 1); |
|
|
lws_callback_on_writable(wsi); |
|
|
lws_callback_on_writable(wsi); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -384,23 +391,6 @@ IZ_ProcedureResult IZ_WSClientWritable(struct lws* wsi) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
IZ_WebsocketMessage* IZ_WSClientCreateMessage(struct lws* wsi, bool binary, void* in, size_t len) { |
|
|
|
|
|
static IZ_WebsocketMessage amsg; |
|
|
|
|
|
amsg.first = (char)lws_is_first_fragment(wsi); |
|
|
|
|
|
amsg.final = (char)lws_is_final_fragment(wsi); |
|
|
|
|
|
amsg.binary = binary; |
|
|
|
|
|
|
|
|
|
|
|
amsg.len = len; |
|
|
|
|
|
/* notice we over-allocate by LWS_PRE */ |
|
|
|
|
|
amsg.payload = malloc(LWS_PRE + len); |
|
|
|
|
|
if (!amsg.payload) { |
|
|
|
|
|
return NULL; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy((char*) amsg.payload + LWS_PRE, in, len); |
|
|
|
|
|
return &amsg; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in, size_t len) { |
|
|
void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in, size_t len) { |
|
|
i32 n = (i32) lws_ring_get_count_free_elements(pss->ring); |
|
|
i32 n = (i32) lws_ring_get_count_free_elements(pss->ring); |
|
|
if (!n) { |
|
|
if (!n) { |
|
@@ -416,8 +406,13 @@ void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in |
|
|
|
|
|
|
|
|
// lwsl_hexdump_notice(in, len); |
|
|
// lwsl_hexdump_notice(in, len); |
|
|
|
|
|
|
|
|
IZ_WebsocketMessage* amsg = IZ_WSClientCreateMessage(wsi, (bool) lws_frame_is_binary(wsi), in, len); |
|
|
|
|
|
if (!amsg) { |
|
|
|
|
|
|
|
|
IZ_WebsocketMessage amsg; |
|
|
|
|
|
i32 result = ( |
|
|
|
|
|
lws_frame_is_binary(wsi) |
|
|
|
|
|
? IZ_WebsocketCreateBinaryMessage(wsi, &amsg, in, len) |
|
|
|
|
|
: IZ_WebsocketCreateTextMessage(wsi, &amsg, in, len) |
|
|
|
|
|
); |
|
|
|
|
|
if (result < 0) { |
|
|
lwsl_user("OOM: dropping\n"); |
|
|
lwsl_user("OOM: dropping\n"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@@ -428,14 +423,14 @@ void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
IZ_App* app = (IZ_App*) vhd->app; |
|
|
IZ_App* app = (IZ_App*) vhd->app; |
|
|
if (amsg->binary) { |
|
|
|
|
|
|
|
|
if (amsg.binary) { |
|
|
IZ_AppHandleNetworkingInboundBinaryEvents(app, in, len); |
|
|
IZ_AppHandleNetworkingInboundBinaryEvents(app, in, len); |
|
|
} else { |
|
|
} else { |
|
|
IZ_AppHandleNetworkingInboundTextEvents(app, in, len); |
|
|
IZ_AppHandleNetworkingInboundTextEvents(app, in, len); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!lws_ring_insert(pss->ring, amsg, 1)) { |
|
|
|
|
|
IZ_WebsocketDestroyMessage(amsg); |
|
|
|
|
|
|
|
|
if (!lws_ring_insert(pss->ring, &amsg, 1)) { |
|
|
|
|
|
IZ_WebsocketDestroyMessage(&amsg); |
|
|
lwsl_user("dropping!\n"); |
|
|
lwsl_user("dropping!\n"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|