UDP sockets & select - is it possible

UDP sockets & select - is it possible

Post by roo » Tue, 07 Mar 1995 07:02:39



  Hi,
   Is it possible to get select to recognise a UDP socket.I tried the
  usual select setup but when i tried to receive a message select did
  not get activated.
   Basically i want to listen to the network and the keyboard simultaneously.

  code looks like:

   fd_set  readfds;

       FD_ZERO(&readfds);
       FD_SET(0, &readfds);     /* listen to keyboard */
       FD_SET(sock, &readfds);  /* listen to UDP socket */

       nfds=select(2,&readfds,NULL,NULL,NULL);

      ^^^  the program just sits here!

  BTW the system is a Sun 4   running SunOS 4.something.

        Jason.
--
###############################################################################


#     Burnside,                ################################################

 
 
 

UDP sockets & select - is it possible

Post by Benard Aart Mesand » Tue, 07 Mar 1995 10:50:31


      Is it possible to get select to recognise a UDP socket.I tried the
     usual select setup but when i tried to receive a message select did
     not get activated.
      Basically i want to listen to the network and the keyboard simultaneously.

     code looks like:

      fd_set  readfds;

          FD_ZERO(&readfds);
          FD_SET(0, &readfds);     /* listen to keyboard */
          FD_SET(sock, &readfds);  /* listen to UDP socket */

          nfds=select(2,&readfds,NULL,NULL,NULL);

         ^^^  the program just sits here!

     BTW the system is a Sun 4   running SunOS 4.something.

is the 2 at least 1 larger than the highest numbered fd you're
selecting on?  to me this looks like you're selecting on fd's 0 and 1
only. I suspect this is not what you want to do since you mention
`keyboard' - I think perhaps you are using stdio, and haven't closed
fd's 1 and 2, and thus your udp socket is at least fildes 3. But to
answer the question you asked, yes it is possible to select on an udp
socket. it works just like any other socket/file descriptor passed to
select.

I really think you probably just need to do this:

          nfds = select (sock + 1, &readfds, NULL, NULL, NULL);
--
%!Ben Mesander    oink       This is not official USGS policy, etc.
newpath 288 396 216 0 361 arc 288 612 moveto 288 180 lineto 288 396
moveto 136 244 lineto 288 396 moveto 440 244 lineto 36 setlinewidth
stroke showpage

 
 
 

UDP sockets & select - is it possible

Post by Mats L|fstr » Wed, 08 Mar 1995 20:46:30


:   Hi,
:    Is it possible to get select to recognise a UDP socket.I tried the

Sure is!

:        nfds=select(2,&readfds,NULL,NULL,NULL);

:       ^^^  the program just sits here!

The first parameter to select() states the size of fd_set, i.e. the number
of files select COULD watch for you. Use the macro FD_SETSIZE instead
as the first argument, and all should work just fine!

        mla

 
 
 

UDP sockets & select - is it possible

Post by B. Wiec » Thu, 09 Mar 1995 23:37:18



writes...
b>

writes:
b>      Is it possible to get select to recognise a UDP socket.I tried
the
b>     usual select setup but when i tried to receive a message select
did
b>     not get activated.
b>      Basically i want to listen to the network and the keyboard
simultaneously.
b>
b>     code looks like:
b>
b>      fd_set  readfds;
b>
b>          FD_ZERO(&readfds);
b>          FD_SET(0, &readfds);     /* listen to keyboard */
b>          FD_SET(sock, &readfds);  /* listen to UDP socket */
b>
b>          nfds=select(2,&readfds,NULL,NULL,NULL);
b>
b>         ^^^  the program just sits here!
b>
b>     BTW the system is a Sun 4   running SunOS 4.something.

Quote:>is the 2 at least 1 larger than the highest numbered fd you're
>selecting on?  to me this looks like you're selecting on fd's 0 and 1
>only. I suspect this is not what you want to do since you mention
>`keyboard' - I think perhaps you are using stdio, and haven't closed
>fd's 1 and 2, and thus your udp socket is at least fildes 3. But to
>answer the question you asked, yes it is possible to select on an udp
>socket. it works just like any other socket/file descriptor passed to
>select.
>I really think you probably just need to do this:

>          nfds = select (sock + 1, &readfds, NULL, NULL, NULL);

Yep. The # 2 seems to be suspiciously small.
Under SunOS 4.1.3 you may want to use "ulimit" to get the correct
value for the "width" in select.

Regards,

                B. Wiecek

--
/* All standard disclaimers included here */
#ifdef DISCLAIMER
#include "blahblah.blah"
#endif
/* Clean up the mess */
#ifdef INSANITY
#undef INSANITY
#endif

 
 
 

UDP sockets & select - is it possible

Post by Casper H.S. D » Fri, 10 Mar 1995 01:17:33



>Yep. The # 2 seems to be suspiciously small.
>Under SunOS 4.1.3 you may want to use "ulimit" to get the correct
>value for the "width" in select.

No, you don't want to do that.  If you wish to give a limit higher than
the highest fd in use + 1, you must make sure
the limit is not higher than the number of bits in the fd sets.

(If the FD_SETSIZE is 256, you can enter at most 256.  The system can
be upgraded and the ulimit may suddenly become 1024 while your program
still has a fixed fd size of 256.  If you use the dynamic limit you'd
be calling select(1024, ...) which will fail because you're using
garbage for the 1024-256 bits.)

Casper

 
 
 

UDP sockets & select - is it possible

Post by Peter La » Sat, 11 Mar 1995 21:36:17


| Newsgroups: comp.unix.programmer

| Path: Austria.EU.net!EU.net!howland.reston.ans.net!news.sprintlink.net!peernews.demon.co.uk!hole.demon.co.uk!root
| X-Newsreader: TIN [version 1.2 PL2]
| Keywords: socket udp select
| Organization: The Hole
| Summary: socket udp select
| X-Posting-Host: hole.demon.co.uk
| Date: Sun, 5 Mar 1995 22:02:39 +0000

| Lines: 27
|
|   Hi,
|    Is it possible to get select to recognise a UDP socket.I tried the
|   usual select setup but when i tried to receive a message select did
|   not get activated.
|    Basically i want to listen to the network and the keyboard simultaneously.
|
|   code looks like:
|    
|    fd_set  readfds;
|    
|        FD_ZERO(&readfds);
|        FD_SET(0, &readfds);     /* listen to keyboard */
|        FD_SET(sock, &readfds);  /* listen to UDP socket */
|
|        nfds=select(2,&readfds,NULL,NULL,NULL);
|
|       ^^^  the program just sits here!
|

You have to use sock+1 instead of 2 as first argument to select().
This argument tells select() the size of the bitmask containing
file descriptors.

              Peter Lang             KNAPP Logistics Automation
           A-8075 Hart bei Graz      Guenther Knapp Strasse 5-7

--
              Peter Lang             KNAPP Logistics Automation
           A-8075 Hart bei Graz      Guenther Knapp Strasse 5-7