Re: SecureTransport and socket I/O
Re: SecureTransport and socket I/O
- Subject: Re: SecureTransport and socket I/O
- From: Frederick Cheung <email@hidden>
- Date: Mon, 29 Sep 2003 23:29:38 +0200
On Monday, Sep 29, 2003, at 23:25 Europe/Paris, Mike Kluev wrote:
On 28 Sep 2003 13:22:56 +0200, Frederick Cheung
<email@hidden>
wrote:
On 9/27/03 11:24 AM, Larry Gerndt wrote:
I posted a few weeks ago about some problems I was having where
SSLRead()
was
returning "sslProtocolErr". My socket was set for blocking mode,
so in
attempting to fix this problem, I switched over to non-blocking
mode and
copied Apples's SSLSample's SocketRead and SocketWrite code, and it
worked
fine. Then I switched the socket back to blocking mode and left
Apple's
SocketRead and SocketWrite code in place and it still worked. So I
did some
investigation, and found out that even in blocking mode, the socket
read
function can return without having read as much data as we
requested,
meaning
you have to read again to get the rest. Apple's sample SocketRead
handles
this case and does the additional reads. By the way, on the first
read,
it's
not returning -1 and EAGAIN, it's returning a positive value,
indicating how
many bytes it did indeed read, but that amount was not as much as I
requested,
so it then reads again to get the rest, and this works great.
My question: I thought in blocking mode, a "read" of a socket
would not
return until as many bytes as requested are read. Was I wrong in
this
assumption?
To answer my own question, I re-read the man page on "read", and I
guess I
was indeed wrong, because the only time a synchronous (i.e blocking)
read
guarantees to not return until the requested number of bytes has
been read
is in the case of reading files which do contain that many bytes
between the
current read point and the end of file. This was news to me and a
valuable
lesson.
The same is true for OT under X (but obviously not on 9)
Then what is the difference between "synchronous blocking" and
"synchronous non-blocking" modes? I would expect the former to
wait for as many bytes as specified and the latter to return
immediately with as many bytes as available.
On OS 9, that was what happened. On OS X, synchronous blocking will
block until there is at least some data available (i think a tcp option
sets how much this is), and return then, whether or not there is the
amount you asked for, whereas non blocking will never block.
Fred
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.