public static void lws_close_reason(lws wsi, lws_close_status status, string buf) { var bytes = QuickJS.Utils.TextUtils.GetNullTerminatedBytes(buf); unsafe { fixed(byte *pointer = bytes) { lws_close_reason(wsi, status, pointer, bytes.Length - 1); } } }
private void SetClose() { if (_wsi.IsValid()) { _is_closing = true; SetReadyState(ReadyState.CLOSING); WSApi.lws_callback_on_writable(_wsi); _wsi = lws.Null; } else { SetReadyState(ReadyState.CLOSED); } }
public static int _callback(lws wsi, lws_callback_reasons reason, IntPtr user, IntPtr @in, size_t len) { var context = WSApi.lws_get_context(wsi); var websocket = GetWebSocket(context); if (websocket == null) { return(-1); } switch (reason) { case lws_callback_reasons.LWS_CALLBACK_CHANGE_MODE_POLL_FD: { return(0); } case lws_callback_reasons.LWS_CALLBACK_CLIENT_RECEIVE: { websocket._is_servicing = true; return(websocket.OnReceive(@in, len)); } case lws_callback_reasons.LWS_CALLBACK_CLIENT_WRITEABLE: { websocket._is_servicing = true; if (websocket._is_closing) { WSApi.lws_close_reason(wsi, lws_close_status.LWS_CLOSE_STATUS_NORMAL, ""); return(-1); } websocket.OnWrite(); return(0); } case lws_callback_reasons.LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: { return(0); } case lws_callback_reasons.LWS_CALLBACK_CLIENT_ESTABLISHED: { websocket._is_servicing = true; websocket._wsi = wsi; websocket.OnConnect(); // _on_connect(websocket, lws_get_protocol(wsi)->name); return(0); } case lws_callback_reasons.LWS_CALLBACK_CLIENT_CONNECTION_ERROR: { websocket._is_servicing = true; websocket.OnError(@in, len); websocket.Destroy(); return(-1); } case lws_callback_reasons.LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: { websocket._is_servicing = true; websocket.OnCloseRequest(@in, len); return(0); } case lws_callback_reasons.LWS_CALLBACK_CLIENT_CLOSED: { websocket.SetClose(); // _duk_lws_close(websocket); websocket.Destroy(); websocket.OnClose(); return(0); } default: { return(0); } } }
public bool Equals(lws other) { return(this == other); }
public static extern unsafe void lws_close_reason(lws wsi, lws_close_status status, byte *buf, size_t len);
public static extern int lws_is_final_fragment(lws wsi);
public static extern int lws_callback_on_writable(lws wsi);
public static extern int lws_frame_is_binary(lws wsi);
public static extern lws_context lws_get_context(lws wsi);
public static extern unsafe int lws_write(lws wsi, byte *buf, size_t len, lws_write_protocol wp);