Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early disposal? Not on my watch! #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Apelsin
Copy link

@Apelsin Apelsin commented Jun 9, 2013

This typo (I'm assuming it's a typo) was causing all kinds of malfeasance in WebSocketClient. This fixie is best viewed with whitespace ignored (git diff -w)

@Apelsin
Copy link
Author

Apelsin commented Jun 9, 2013

For your convenience:

C:\code\fb2\Alchemy-Websockets>git diff --cached -w HEAD~
diff --git a/src/Alchemy/WebSocketClient.cs b/src/Alchemy/WebSocketClient.cs
index 2472078..12ad613 100644
--- a/src/Alchemy/WebSocketClient.cs
+++ b/src/Alchemy/WebSocketClient.cs
@@ -148,8 +148,6 @@ namespace Alchemy
                 connectError = true;
             }

-            using (_context = new Context(null, _client))
-            {
             _context = new Context(null, _client);
             _context.BufferSize = 512;
             _context.UserContext.DataFrame = new DataFrame();
@@ -176,7 +174,6 @@ namespace Alchemy
                 NewClients.Enqueue(_context);
             }
         }
-        }

@steforster
Copy link

Without this fix, the c# WebSocketClient does not work at all (see issue #78).
@segor has fixed it in his fork also.
Additionally, the WebSocketClient throws a null-reference exception (on _context), when the socket cannot be opened.
I fixed it in WebSocketClient.Disconnect() as follows:

@@ -348,10 +348,13 @@ namespace Alchemy

        var bytes = dataFrame.AsFrame()[0].Array;

-            ReadyState = ReadyStates.CLOSING;
+            if (_context != null && ReadyState == ReadyStates.OPEN)
+            {
+                ReadyState = ReadyStates.CLOSING;
+                bytes[0] = 0x88;
+                _context.UserContext.Send(bytes);
+            }

-            bytes[0] = 0x88;
-            _context.UserContext.Send(bytes);
             _client.Close();
            _client = null;
             ReadyState = ReadyStates.CLOSED;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants