Esempio n. 1
0
        private static WebSocket GetWebSocket(lws_context context)
        {
            var count = _websockets.Count;

            for (var i = 0; i < count; i++)
            {
                var websocket = _websockets[i];
                if (websocket._context == context)
                {
                    return(websocket);
                }
            }

            return(null);
        }
Esempio n. 2
0
        // _duk_lws_destroy
        private void Destroy()
        {
            if (_is_context_destroyed)
            {
                return;
            }

            if (_is_polling)
            {
                _is_context_destroying = true;
                return;
            }

            SetReadyState(ReadyState.CLOSED);
            _is_context_destroyed = true;
            if (_context.IsValid())
            {
                // WSApi.ulws_destroy(_context);
                _context = lws_context.Null;
            }

            while (_pending.Count > 0)
            {
                var packet = _pending.Dequeue();
                packet.Release();
            }
            _bufferedAmount = 0;

            if (_buffer != null)
            {
                _buffer.Release();
                _buffer = null;
            }
            var runtime = ScriptEngine.GetRuntime(_jsContext);

            if (runtime != null)
            {
                runtime.OnUpdate  -= Update;
                runtime.OnDestroy -= Destroy;
            }
            _websockets.Remove(this);
            // UnityEngine.Debug.LogWarning("ws.destroy");
        }
Esempio n. 3
0
 // buffer: buffer for recv
 private WebSocket(ByteBuffer buffer, string url, List <string> protocols)
 {
     _url       = url;
     _buffer    = buffer;
     _protocols = protocols != null?protocols.ToArray() : new string[]
     {
         ""
     };
     _websockets.Add(this);
     do
     {
         if (_protocols != null && _protocols.Length > 0)
         {
             _context = WSApi.ulws_create(_protocols[0], _callback, 1024 * 4, 1024 * 4);
             if (_context.IsValid())
             {
                 SetReadyState(ReadyState._CONSTRUCTED);
                 break;
             }
         }
         SetReadyState(ReadyState.CLOSED);
     } while (false);
 }
Esempio n. 4
0
 public bool Equals(lws_context other)
 {
     return(this == other);
 }
Esempio n. 5
0
 public static extern int lws_service(lws_context context, int timeout_ms);
Esempio n. 6
0
 public static extern void ulws_destroy(lws_context context);
Esempio n. 7
0
 public static extern unsafe lws ulws_connect(lws_context context, byte *protocol_names, ulws_ssl_type ssl_type, byte *host, byte *address, byte *path, int port);