Fix for issue #30
This commit is contained in:
parent
a96a6f2226
commit
8448f0a30b
@ -1509,52 +1509,60 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// As server, used to broadcast
|
// As server, used to broadcast
|
||||||
internal void Send (
|
internal void Send (Opcode opcode, byte [] data, Dictionary<CompressionMethod, byte []> cache)
|
||||||
Opcode opcode, byte [] data, Dictionary<CompressionMethod, byte []> cache)
|
|
||||||
{
|
{
|
||||||
lock (_forSend) {
|
lock (_forSend) {
|
||||||
try {
|
lock (_forConn) {
|
||||||
byte [] cached;
|
if (_readyState != WebSocketState.OPEN)
|
||||||
if (!cache.TryGetValue (_compression, out cached)) {
|
return;
|
||||||
cached = WsFrame.CreateFrame (
|
|
||||||
Fin.FINAL,
|
|
||||||
opcode,
|
|
||||||
Mask.UNMASK,
|
|
||||||
data.Compress (_compression),
|
|
||||||
_compression != CompressionMethod.NONE).ToByteArray ();
|
|
||||||
|
|
||||||
cache.Add (_compression, cached);
|
try {
|
||||||
|
byte [] cached;
|
||||||
|
if (!cache.TryGetValue (_compression, out cached)) {
|
||||||
|
cached = WsFrame.CreateFrame (
|
||||||
|
Fin.FINAL,
|
||||||
|
opcode,
|
||||||
|
Mask.UNMASK,
|
||||||
|
data.Compress (_compression),
|
||||||
|
_compression != CompressionMethod.NONE)
|
||||||
|
.ToByteArray ();
|
||||||
|
|
||||||
|
cache.Add (_compression, cached);
|
||||||
|
}
|
||||||
|
|
||||||
|
_stream.Write (cached);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_logger.Fatal (ex.ToString ());
|
||||||
|
error ("An exception has occurred while sending a data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
send (cached);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
_logger.Fatal (ex.ToString ());
|
|
||||||
error ("An exception has occurred while sending a data.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As server, used to broadcast
|
// As server, used to broadcast
|
||||||
internal void Send (
|
internal void Send (Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
|
||||||
Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
|
|
||||||
{
|
{
|
||||||
lock (_forSend) {
|
lock (_forSend) {
|
||||||
try {
|
lock (_forConn) {
|
||||||
Stream cached;
|
if (_readyState != WebSocketState.OPEN)
|
||||||
if (!cache.TryGetValue (_compression, out cached)) {
|
return;
|
||||||
cached = stream.Compress (_compression);
|
|
||||||
cache.Add (_compression, cached);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cached.Position = 0;
|
|
||||||
|
|
||||||
sendFragmented (
|
try {
|
||||||
opcode, cached, Mask.UNMASK, _compression != CompressionMethod.NONE);
|
Stream cached;
|
||||||
}
|
if (!cache.TryGetValue (_compression, out cached)) {
|
||||||
catch (Exception ex) {
|
cached = stream.Compress (_compression);
|
||||||
_logger.Fatal (ex.ToString ());
|
cache.Add (_compression, cached);
|
||||||
error ("An exception has occurred while sending a data.");
|
}
|
||||||
|
else
|
||||||
|
cached.Position = 0;
|
||||||
|
|
||||||
|
sendFragmented (opcode, cached, Mask.UNMASK, _compression != CompressionMethod.NONE);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_logger.Fatal (ex.ToString ());
|
||||||
|
error ("An exception has occurred while sending a data.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user