2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
1.4 KiB

  1. #include "IZ_websocket.h"
  2. void IZ_WebsocketInitialize(IZ_Websocket* ws) {
  3. ws->context = NULL;
  4. ws->interrupted = false;
  5. }
  6. IZ_ProcedureResult IZ_WebsocketHandle(IZ_Websocket* ws) {
  7. return lws_service_tsi(ws->context, -1, 0);
  8. }
  9. void IZ_WebsocketCancelService(IZ_Websocket* ws) {
  10. ws->interrupted = true;
  11. lws_cancel_service(ws->context);
  12. }
  13. void IZ_WebsocketTeardown(IZ_Websocket* ws) {
  14. lws_context_destroy(ws->context);
  15. ws->context = NULL;
  16. }
  17. void IZ_WebsocketDestroyMessage(IZ_WebsocketMessage* msg) {
  18. free(msg->payload);
  19. msg->payload = NULL;
  20. msg->len = 0;
  21. }
  22. IZ_ProcedureResult IZ_WebsocketCreateBinaryMessage(struct lws* wsi, IZ_WebsocketMessage* amsg, void* in, size_t len) {
  23. /* notice we over-allocate by LWS_PRE */
  24. amsg->payload = malloc(LWS_PRE + len);
  25. if (!amsg->payload) {
  26. return -1;
  27. }
  28. amsg->first = (u8) lws_is_first_fragment(wsi);
  29. amsg->final = (u8) lws_is_final_fragment(wsi);
  30. amsg->binary = true;
  31. amsg->len = len;
  32. memcpy((char*) amsg->payload + LWS_PRE, in, len);
  33. return 0;
  34. }
  35. IZ_ProcedureResult IZ_WebsocketCreateTextMessage(struct lws* wsi, IZ_WebsocketMessage* amsg, void* in, size_t len) {
  36. /* notice we over-allocate by LWS_PRE */
  37. amsg->payload = malloc(LWS_PRE + len);
  38. if (!amsg->payload) {
  39. return -1;
  40. }
  41. amsg->first = (u8) lws_is_first_fragment(wsi);
  42. amsg->final = (u8) lws_is_final_fragment(wsi);
  43. amsg->binary = false;
  44. amsg->len = len;
  45. memcpy((char*) amsg->payload + LWS_PRE, in, len);
  46. return 0;
  47. }