diff --git a/Example/Example.pidb b/Example/Example.pidb index 12730c7f..c0227b1c 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/Program.cs b/Example/Program.cs index 0121459e..5e604887 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -73,9 +73,9 @@ namespace Example ThreadPool.QueueUserWorkItem(notifyMsg); - //using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo")) + using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo")) //using (WebSocket ws = new WebSocket("wss://echo.websocket.org", "echo")) - using (WebSocket ws = new WebSocket("ws://localhost:4649")) + //using (WebSocket ws = new WebSocket("ws://localhost:4649")) { ws.OnOpen += (sender, e) => { diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 3b067070..4a970e0f 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index 076da547..8edb0c11 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 063391d9..2d652b4c 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index b8e801f7..d86c09d4 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/Example1.pidb b/Example1/Example1.pidb index d594e6bc..fb7ef51e 100644 Binary files a/Example1/Example1.pidb and b/Example1/Example1.pidb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 15772cca..f785a051 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index 55229d98..f0518ead 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 063391d9..2d652b4c 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index b8e801f7..d86c09d4 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 0aef22a7..6ccf2017 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index 25f033bb..0ac5f698 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 063391d9..2d652b4c 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index b8e801f7..d86c09d4 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 5a9e5b46..7cc2978a 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index b0d9cb70..adbd1579 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 063391d9..2d652b4c 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index b8e801f7..d86c09d4 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 5bcd9ab9..481568ba 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -66,14 +66,13 @@ namespace WebSocketSharp private string _binaryType; private HttpListenerWebSocketContext _context; private IPEndPoint _endPoint; - private AutoResetEvent _exitedMessageLoop; + private AutoResetEvent _exitMessageLoop; private string _extensions; private Object _forClose; private Object _forSend; private int _fragmentLen; private bool _isClient; private bool _isSecure; - private Thread _msgThread; private NetworkStream _netStream; private string _protocol; private string _protocols; @@ -355,13 +354,8 @@ namespace WebSocketSharp private void closeHandshake(WsFrame frame) { if (send(frame) && !Thread.CurrentThread.IsBackground) - { - if (_isClient && _msgThread != null) - _msgThread.Join(5 * 1000); - - if (!_isClient && _exitedMessageLoop != null) - _exitedMessageLoop.WaitOne(5 * 1000); - } + if (_exitMessageLoop != null) + _exitMessageLoop.WaitOne(5 * 1000); ReadyState = WsState.CLOSED; } @@ -673,14 +667,6 @@ namespace WebSocketSharp } } - private void messageLoop() - { - while (_readyState == WsState.OPEN) - { - message(); - } - } - private void messageLoopCallback(IAsyncResult ar) { Action messageInvoker = (Action)ar.AsyncState; @@ -689,11 +675,10 @@ namespace WebSocketSharp if (_readyState == WsState.OPEN) { messageInvoker.BeginInvoke(messageLoopCallback, messageInvoker); + return; } - else - { - _exitedMessageLoop.Set(); - } + + _exitMessageLoop.Set(); } private void pong(PayloadData data) @@ -1042,24 +1027,15 @@ namespace WebSocketSharp private void startMessageThread() { - if (_isClient) + _exitMessageLoop = new AutoResetEvent(false); + + Action messageInvoker = () => { - _msgThread = new Thread(new ThreadStart(messageLoop)); - _msgThread.IsBackground = true; - _msgThread.Start(); - } - else - { - _exitedMessageLoop = new AutoResetEvent(false); - Action messageInvoker = () => - { - if (_readyState == WsState.OPEN) - { - message(); - } - }; - messageInvoker.BeginInvoke(messageLoopCallback, messageInvoker); - } + if (_readyState == WsState.OPEN) + message(); + }; + + messageInvoker.BeginInvoke(messageLoopCallback, messageInvoker); } #endregion diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 063391d9..2d652b4c 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index b8e801f7..d86c09d4 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 478996cb..4e75caaa 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ