예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
            }
            }
        }