diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 74766c94..56d1bf86 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 be7c63a4..6d03fa7b 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 0c86b374..a0d16988 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 38dc6da5..6e41e049 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/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index c9be303f..756dd7e9 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 23b85d00..78b2dfa8 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 0c86b374..a0d16988 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 38dc6da5..6e41e049 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 0fe39737..a7493886 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 64345177..a0e9a7ff 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 0c86b374..a0d16988 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 38dc6da5..6e41e049 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 c2db4d8d..d71ce609 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 64f4ca81..6225097c 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 0c86b374..a0d16988 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 38dc6da5..6e41e049 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/Server/SessionManager.cs b/websocket-sharp/Server/SessionManager.cs index 0cfaf816..5cb26508 100644 --- a/websocket-sharp/Server/SessionManager.cs +++ b/websocket-sharp/Server/SessionManager.cs @@ -125,7 +125,7 @@ namespace WebSocketSharp.Server { #endregion - #region Private Method + #region Private Methods private Dictionary copySessions() { @@ -175,10 +175,7 @@ namespace WebSocketSharp.Server { lock (_syncRoot) { foreach (var service in _sessions.Values) - if (_isStopped || _isSweeping) - service.Send(data); - else - service.SendAsync(data); + service.Send(data); } } @@ -187,10 +184,7 @@ namespace WebSocketSharp.Server { lock (_syncRoot) { foreach (var service in _sessions.Values) - if (_isStopped || _isSweeping) - service.Send(data); - else - service.SendAsync(data); + service.Send(data); } } diff --git a/websocket-sharp/Server/WebSocketService.cs b/websocket-sharp/Server/WebSocketService.cs index 455f2f91..38d5cc30 100644 --- a/websocket-sharp/Server/WebSocketService.cs +++ b/websocket-sharp/Server/WebSocketService.cs @@ -193,26 +193,6 @@ namespace WebSocketSharp.Server { _socket.Send(data); } - public void SendAsync(byte[] data) - { - WaitCallback sendCb = (state) => - { - Send(data); - }; - - ThreadPool.QueueUserWorkItem(sendCb); - } - - public void SendAsync(string data) - { - WaitCallback sendCb = (state) => - { - Send(data); - }; - - ThreadPool.QueueUserWorkItem(sendCb); - } - public void SendTo(string id, byte[] data) { if (!IsBound) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 89d2e011..69106e0f 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1041,6 +1041,26 @@ namespace WebSocketSharp { return send(frame); } + private void sendAsync(Opcode opcode, byte[] data, Action completed) + { + sendAsync(opcode, new MemoryStream(data), completed); + } + + private void sendAsync(Opcode opcode, Stream stream, Action completed) + { + Action action = send; + AsyncCallback callback = null; + callback = (ar) => + { + action.EndInvoke(ar); + stream.Close(); + if (!completed.IsNull()) + completed(); + }; + + action.BeginInvoke(opcode, stream, callback, null); + } + private long sendFragmented(Opcode opcode, Stream stream) { var length = stream.Length; @@ -1345,6 +1365,40 @@ namespace WebSocketSharp { } } + public void SendAsync(string data, Action completed) + { + if (data.IsNull()) + { + onError("'data' must not be null."); + return; + } + + var buffer = Encoding.UTF8.GetBytes(data); + sendAsync(Opcode.TEXT, buffer, completed); + } + + public void SendAsync(byte[] data, Action completed) + { + if (data.IsNull()) + { + onError("'data' must not be null."); + return; + } + + sendAsync(Opcode.BINARY, data, completed); + } + + public void SendAsync(FileInfo file, Action completed) + { + if (file.IsNull()) + { + onError("'file' must not be null."); + return; + } + + sendAsync(Opcode.BINARY, file.OpenRead(), completed); + } + #endregion } } diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 0c86b374..a0d16988 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 38dc6da5..6e41e049 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 c8eb772a..74acf889 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ