On Mon, Sep 24, 2012 at 11:09 PM, Andrew Jenkins
<[email protected]> wrote:
> In Node v0.8.9, if I write to a stream after calling end() but before the
> stream write queue is drained, it will succeed.  If I write to an ended
> stream in the drain event, it will succeed.  For instance, this code causes
> "This data written after end()" to be written once, and "Even more data
> after end" to be written indefinitely to the socket, even though the socket
> is not writable.  Also the close event never occurs:
>
> var net = require('net');
> var assert = require('assert');
>
> var sock = new net.Socket();
> sock.on('close', function() { console.log('Closed'); });
> sock.connect({port: 12345}, function connectCb() {
>   sock.write('Hello world');
>   sock.end();
>   sock.on('drain', function () {
>     assert(sock.writable == false);
>     sock.write('Even more data after end');
>   });
>   assert(sock.writable == false);
>   sock.write('This data written after end()');
> });
>
> $ nc -l 12345
>
> Is this behavior intended?
>
> The stream documentation [1] says end "will allow queued write data to be
> sent before closing the stream."  The Joyent stream wiki [2] says that after
> close() (renamed end()), "Further calls to write() after calling this method
> will throw an error."  My possibly incorrect interpretation of this
> documentation suggests that only "Hello world" should be written.
>
> If I defer the socket write for one process.nextTick() instead, it fails
> with EPIPE.
>
> Thanks,
> Andrew Jenkins
>
> [1] http://nodejs.org/api/stream.html#stream_stream_end
> [2] https://github.com/joyent/node/wiki/Streams

Yes, it's intentional (if somewhat organically grown to be that way).
The quote from the streams documentation doesn't apply because you're
not using the socket as a stream.

-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to