Article View: borland.public.cppbuilder.internet.socket
Article #1904Re: TClientSocket OnRead event issues
From: Remy Lebeau (TeamB)
Date: Tue, 26 Sep 2006 16:56
Date: Tue, 26 Sep 2006 16:56
58 lines
3830 bytes
3830 bytes
"Arnoud" <vult-r@endless-online.com> wrote in message
news:4519327b@newsgroups.borland.com...
> OnRead() seems to trigger only *once*, and then expect our
> applications to do at least one Read operation to trigger again.
That is how non-blocking sockets are designed to work. The socket only
sends one OnRead event to let you know that data is available, and then your
application has to read what is available before a new OnRead event can be
triggered again. This is explained in the socket API documentation:
(begin quote)
The Windows Sockets DLL will not continually flood an application with
messages for a particular network event. Having successfully posted
notification of a particular event to an application window, no further
message(s) for that network event will be posted to the application window
until the application makes the function call which implicitly re-enables
notification of that network event.
Event Re-enabling function
FD_READ recv, recvfrom, WSARecv, or WSARecvFrom
...
Any call to the re-enabling routine, even one which fails, results in
re-enabling of message posting for the relevant event.
For FD_READ, FD_OOB, and FD_ACCEPT events, message posting is
"level-triggered." This means that if the re-enabling routine is called and
the relevant condition is still met after the call, a WSAAsyncSelect message
is posted to the application. This allows an application to be event-driven
and not be concerned with the amount of data that arrives at any one time.
Consider the following sequence:
1. Network transport stack receives 100 bytes of data on socket s and
causes Windows Sockets 2 to post an FD_READ message.
2. The application issues recv(s, buffptr, 50, 0) to read 50 bytes.
3. Another FD_READ message is posted since there is still data to be
read.
With these semantics, an application need not read all available data in
response to an FD_READ message - a single recv in response to each FD_READ
message is appropriate. If an application issues multiple recv calls in
response to a single FD_READ, it can receive multiple FD_READ messages. Such
an application may need to disable FD_READ messages before starting the recv
calls by calling WSAAsyncSelect with the FD_READ event not set.
(end quote)
You DO NOT, however, need to do a "garbage" read to get the OnRead event to
trigger in the first place. If you connect to a server and do not do any
reads at all, you will still get an OnRead event when the server sends data.
I have been using TClientSocket for years and never had any problems with
that.
Gambit
Technical Details
Message-ID:
<45195c64$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4508a026@newsgroups.borland.com> <4508a3f3$2@newsgroups.borland.com> <4508aab1$1@newsgroups.borland.com> <4508b143@newsgroups.borland.com> <450949ba$1@newsgroups.borland.com> <45095b16@newsgroups.borland.com> <45096c00@newsgroups.borland.com> <45098f13@newsgroups.borland.com> <4519327b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,6164f1b08fcaf5c2 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4508a026@newsgroups.borland.com> <4508a3f3$2@newsgroups.borland.com> <4508aab1$1@newsgroups.borland.com> <4508b143@newsgroups.borland.com> <450949ba$1@newsgroups.borland.com> <45095b16@newsgroups.borland.com> <45096c00@newsgroups.borland.com> <45098f13@newsgroups.borland.com> <4519327b@newsgroups.borland.com> Subject: Re: TClientSocket OnRead event issues Date: Tue, 26 Sep 2006 09:56:57 -0700 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 69.169.4.232 Message-ID: <45195c64$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1159289956 69.169.4.232 (26 Sep 2006 09:59:16 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail