comp.lang.ada
 help / color / mirror / Atom feed
From: "Tarjei T. Jensen" <tarjei@online.no>
Subject: Re: [OT] Two sockets questions
Date: Sun, 11 May 2003 20:23:14 +0200
Date: 2003-05-11T20:23:14+02:00	[thread overview]
Message-ID: <ozwva.11487$b71.220478@news4.e.nsc.no> (raw)
In-Reply-To: 3ebcbefb$1@news.wineasy.se


"Tarjei T. Jensen" <tarjei.jensen@akerkvaerner.com> wrote in message
news:3ebcbefb$1@news.wineasy.se...
>
> "Jano"  wrote
> > I'm a bit afraid of using so many (say two thousands) tasks (are they
> > really that light? What computer is necessary for that number? I have a
> > pretty decent one, but...) but really I haven't past experiences about
> > so many threads. However, as I've never seen an application so task
> > intensive, I've think that that is for some reason (my httpd apache uses
> > 253 and is the most I've seen).

New answer (google is my friend)

The Winsock programmers FAQ http://tangentsoft.net/wskfaq/ says
2.8 - Winsock keeps returning the error WSAEWOULDBLOCK. What's wrong with my
program?
Not a thing. WSAEWOULDBLOCK is a perfectly normal occurrence in programs
using non-blocking and asynchronous sockets. It's Winsock's way of telling
your program "I can't do that right now, because I would have to block to do
so."

The next question is, how do you know when it's safe to try again? In the
case of asynchronous sockets, Winsock will send you an FD_WRITE message
after a failed send() call when it is safe to write; it will send you an
FD_READ message after a recv() call when more data arrives on that socket.
Similarly, in a non-blocking sockets program that uses select(), the
writefds will be set when it's okay to write, and the readfds will be set if
there is data to read.

Note that Win9x has a bug where select() can fail to block on a nonblocking
socket. It will signal one of the sockets, which will cause your program to
call recv() or send() or similar. That function will return WSAEWOULDBLOCK,
which can be quite a surprise. So, a program using select() under Win9x has
to be able to deal with this error at any time.

This gets to a larger issue: whenever you use some form of nonblocking
sockets, you have to be prepared for WSAEWOULDBLOCK at any time. It's simply
a matter of defensive programming, just like checking for null pointers.



Quote from the Unix socket FAQ (http://www.developerweb.net/sock-faq/):
9. What are the pros/cons of select(), non-blocking I/O and SIGIO?

Using non-blocking I/O means that you have to poll sockets to see if there
is data to be read from them. Polling should usually be avoided since it
uses more CPU time than other techniques.

Using SIGIO allows your application to do what it does and have the
operating system tell it (with a signal) that there is data waiting for it
on a socket. The only drawback to this soltion is that it can be confusing,
and if you are dealing with multiple sockets you will have to do a select()
anyway to find out which one(s) is ready to be read.

Using select() is great if your application has to accept data from more
than one socket at a time since it will block until any one of a number of
sockets is ready with data. One other advantage to select() is that you can
set a time-out value after which control will be returned to you whether any
of the sockets have data for you or not.


-- End of Quote --

Related Web sites:

Winsock tuning FAQ http://www.cerberus-sys.com/~belleisl/mtu_mss_rwin.html

Raw IP Networking FAQ http://www.whitefang.com/rin/

Unix programming FAQ http://www.erlenstar.demon.co.uk/unix/

The TCP/IP FAQ http://www.itprc.com/tcpipfaq/default.htm





  parent reply	other threads:[~2003-05-11 18:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-07 18:03 [OT] Two sockets questions Jano
2003-05-07 18:22 ` Samuel Tardieu
2003-05-07 19:52   ` Stephen Leake
2003-05-07 20:08     ` David C. Hoos
2003-05-07 22:33     ` Jano
2003-05-08  9:10       ` Samuel Tardieu
2003-05-08 21:35         ` Jano
2003-05-09  8:14           ` Samuel Tardieu
2003-05-09 14:32             ` Jano
2003-05-10 14:06         ` Jano
2003-05-10 18:01           ` tmoran
2003-05-10 21:27             ` Samuel Tardieu
2003-05-11 18:01               ` tmoran
2003-05-08 17:48       ` Stephen Leake
2003-05-08 18:42         ` Samuel Tardieu
2003-05-08 21:41           ` Jano
2003-05-08 21:48           ` Jano
2003-05-08 22:35             ` tmoran
2003-05-09 14:42               ` Jano
2003-05-10  8:57                 ` Tarjei T. Jensen
2003-05-10 16:55                   ` Simon Wright
2003-05-11 18:23                   ` Tarjei T. Jensen [this message]
2003-05-11  2:05                 ` tmoran
2003-05-08 21:40         ` Jano
2003-05-07 20:02   ` Jano
2003-05-08  8:57     ` Samuel Tardieu
2003-05-08 21:39       ` Jano
2003-05-08 10:14   ` Preben Randhol
2003-05-08 11:09     ` Samuel Tardieu
2003-05-08 21:40       ` Jano
2003-05-09  8:19         ` Samuel Tardieu
2003-05-08 18:06     ` tmoran
2003-05-07 20:09 ` tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox