Skip to content

Commit

Permalink
Merge pull request Quobject#21 from gamer3dx/exceptionfix
Browse files Browse the repository at this point in the history
Fixed InvalidOperationException: Collection was modified in WebSocket.Write
  • Loading branch information
mattqs committed Mar 29, 2016
2 parents cc962b0 + 9c36a61 commit 87b3234
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 11 additions & 3 deletions Src/EngineIoClientDotNet.mono/Client/Socket_net35.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ internal void OnDrain()

//log.Info(string.Format("OnDrain2 PrevBufferLen={0} WriteBuffer.Count={1}", PrevBufferLen, WriteBuffer.Count));

WriteBuffer.RemoveRange(0, PrevBufferLen);
lock (WriteBuffer)
{
WriteBuffer.RemoveRange(0, PrevBufferLen);
}
CallbackBuffer.RemoveRange(0, PrevBufferLen);


Expand Down Expand Up @@ -602,7 +605,10 @@ private void SendPacket(Packet packet, Action fn)
Emit(EVENT_PACKET_CREATE, packet);
//var log = LogManager.GetLogger(Global.CallerName());
//log.Info(string.Format("SendPacket WriteBuffer.Add(packet) packet ={0}",packet.Type));
WriteBuffer.Add(packet);
lock (WriteBuffer)
{
WriteBuffer.Add(packet);
}
CallbackBuffer.Add(fn);
Flush();
}
Expand Down Expand Up @@ -1041,7 +1047,9 @@ private void OnClose(string reason, Exception desc = null)

EasyTimer.SetTimeout(() =>
{
WriteBuffer = new List<Packet>();
lock (WriteBuffer){
WriteBuffer.Clear();
}
CallbackBuffer = new List<Action>();

PrevBufferLen = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ void ws_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
protected override void Write(List<Parser.Packet> packets)
{
Writable = false;
foreach (var packet in packets)
lock (packets)
{
Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this));
foreach (var packet in packets)
{
Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this));
}
}

// fake drain
Expand Down

0 comments on commit 87b3234

Please sign in to comment.