LearnBoost/socket.io-client — pull request #377 by arttu (2012-01-27 15:06:25+00:00)
Title: Emit the 'connect' event before flushing the buffer

First of all, I'm sorry that I don't have tests for this patch, but I'm running on node 0.6 series and right now there is no working test suite for my choice of version. I'll be happy to provide test cases when you guys get your stuff ready for 0.6.

The patch emits the 'connect' event **before** the data in buffer is sent
to the server, preventing potential data loss during reconnect process.
Data losses happen specially when using namespaces.

Fixes a reconnect scenario where the following sequence of events occurs:
1) internet connection drops
2) client tries to send data to server, not knowing yet that the connection is lost (this data will still be lost)
3) after configured timeout, client notices that the connection was dropped and starts the reconnect process
4) client tries to send data to server while reconnecting, data is gathered into the client buffer
5) internet connection is re-estabilished
6) client re-connects to and handshakes with the server
7) client sends a connect event (to '/' namespace)
8) the content of client's buffer is sent to the server
9) client sends a connect event to a namespaced endpoint

Previously when a connection was made, client tried to flush the buffer before emitting the 'connect' event to a namespaced connection causing buffered data - messages to a namespaced endpoint - to be lost.