On 06/09/2012, at 23:11, Mark Volkmann wrote:
My understanding is that node won't/shouldn't emit/dispatch any 'data' events to the socket 'socket' until *after* having called cb(socket), 'cb' being the callback function passed on to .createServer(cb).
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
done. Said handshake is complete when the server accepts theThe client queues write requests until the connection handshake is
connection, which node does right before it calls your connListener
function.
--
It sounds like you might be misunderstanding something fundamental about node/Javascript - it's all single threaded, and (at least the networking stuff) is event-based (specifically a stream of sequential events, since there's no concurrency). In your example, while it's running line 5, there's no way it's going to miss anything because that's the only code that is running, nothing could possibly be pumping the event loop. Until your function returns from handling the event, node is not going to handle the next event coming from the socket. Even if the data has been sent and buffered in the kernel for your server process, it's not going to fire any events until node tries to read from it/pumps the event loop. Lots of node APIs rely on this kind of behavior (e.g. HTTP request/response stuff similarly lets you set up event listeners in a connection event before it could possibly fire any data events). Hope this helps!
I don't doubt you. I just want to see that documented somewhere or clearly see how that is enforced in the code. I have looked at net.js. It's not the easiest code to follow. If it's clear from that code, I could use some pointers on where to look.I'll try to make my concern more clear below with very simple code for server.js and client.js that really runs. Run "node server" in one window and "node client" in another.The numbered comments indicate the order in which I expect the lines to execute.It seems clear to me that 4 could run before 5. If that happens, how is it that the server still gets that message? Is the message being buffered until connListener completes?
--
On Fri, Sep 7, 2012 at 7:05 PM, Mark Volkmann <r.mark....@gmail.com> wrote:
I don't doubt you. I just want to see that documented somewhere or clearly see how that is enforced in the code. I have looked at net.js. It's not the easiest code to follow. If it's clear from that code, I could use some pointers on where to look.I'll try to make my concern more clear below with very simple code for server.js and client.js that really runs. Run "node server" in one window and "node client" in another.The numbered comments indicate the order in which I expect the lines to execute.It seems clear to me that 4 could run before 5. If that happens, how is it that the server still gets that message? Is the message being buffered until connListener completes?
4 always runs before 5. The data event cannot be triggered unless something is written to the socket. This is provided the server.js file is run first and then client.js. The other way round will not work as it will throw a ECONNREFUSED on connect() at line 3 (provided the server has not done a listen() yet).Here is the flow:Behind the scenes, the event loop is notified of a new connection. It accept()'s the connection. Once accept()ed the connListener callback is