TLS socket write + drain

118 views
Skip to first unread message

Joran Dirk Greef

unread,
Jul 17, 2013, 10:01:50 AM7/17/13
to nod...@googlegroups.com
I have a question regarding how TLS socket write works and am going through the source now too.

The documentation details this behavior as:

"Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. 'drain' will be emitted when the buffer is again free. The optional callback parameter will be executed when the data is finally written out - this may not be immediately."

If I pass a 1mb-2mb buffer to write(), does a true return code or executed callback guarantee that I can overwrite parts of that buffer, without changing any data that was passed to the write?

Ben Noordhuis

unread,
Jul 17, 2013, 5:02:02 PM7/17/13
to nod...@googlegroups.com
Yes.

Joran Greef

unread,
Jul 19, 2013, 7:22:33 AM7/19/13
to nod...@googlegroups.com
Thanks Ben, does a return code of true and the callback being called mean exactly the same thing? Do both give the same guarantee?

The reason I ask is because I am pre-allocating a buffer for a websocket server, and this is overwriting the buffer as soon as write returns true or the callback is fired. I noticed that for large writes it's overwriting data before it gets to the client.

Joran Greef

RONOMON



--
--
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

---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/BC2ULjPqTi4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Ben Noordhuis

unread,
Jul 19, 2013, 7:38:01 AM7/19/13
to nod...@googlegroups.com
On Fri, Jul 19, 2013 at 1:22 PM, Joran Greef <jorandi...@gmail.com> wrote:
> Thanks Ben, does a return code of true and the callback being called mean
> exactly the same thing? Do both give the same guarantee?
>
> The reason I ask is because I am pre-allocating a buffer for a websocket
> server, and this is overwriting the buffer as soon as write returns true or
> the callback is fired. I noticed that for large writes it's overwriting data
> before it gets to the client.
>
> Joran Greef
>
> RONOMON

Yes, they mean the same thing / come with the same guarantees - that
the contents of the buffer has been handed off to the operating
system.
Reply all
Reply to author
Forward
0 new messages