Article View: borland.public.cppbuilder.internet.socket
Article #5032Re: select() & ioctlsocket() problem
From: Remy Lebeau (TeamB)
Date: Sat, 23 Oct 2004 19:13
Date: Sat, 23 Oct 2004 19:13
39 lines
2807 bytes
2807 bytes
"PaoloItaly" <paolot@FAKETHESPAMMERsirius-es.it> wrote in message
news:4178ed30@newsgroups.borland.com...
> - select() return immediately (also if timeout parameter is NULL),
> returning 1 (no error) but this socket should be closed/invalid
You did not read the documentation for select(), did you? IT is doing
exactly what it should be doing:
The parameter readfds identifies those sockets which are to be checked
for readability. If the socket is currently listening, it will be marked as
readable if an incoming connection request has been received, so that an
accept is guaranteed to complete without blocking. For other sockets,
readability means that queued data is available for reading so that a recv
or recvfrom is guaranteed not to block.
***
For connection-oriented sockets, readability can also indicate that a
close request has been received from the peer. If the virtual circuit was
closed gracefully, then a recv will return immediately with zero bytes read.
If the virtual circuit was reset, then a recv will complete immediately with
an error code, such as WSAECONNRESET. The presence of out-of-band data will
be checked if the socket option SO_OOBINLINE has been enabled (see
setsockopt).
***
In other words, you detect a graceful disconnect when select() returns that
the socket is readable and then recv() returns 0 (or an error) immediately.
> If i call recv() the function return SOCKET_ERROR (correct) but
> i've to read data in a static buffer and i wish to allocate memory
> dinamically knowing the exact size
There is no data to receive in this case since the socket is being
disconnected, thus there is nothing to allocate to begin with.
Gambit
Technical Details
Message-ID:
<417aad3c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4178ed30@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,594e3ed9f24a168f 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: <4178ed30@newsgroups.borland.com> Subject: Re: select() & ioctlsocket() problem Date: Sat, 23 Oct 2004 12:13:43 -0700 Lines: 41 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: 68.69.17.41 Message-ID: <417aad3c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1098558780 68.69.17.41 (23 Oct 2004 12:13:00 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail