[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

the exception of select()

Dear Sirs:
   I use a SUN-OS4.1.3 and the client PC is Win95.
I use the select() function call with recv() and send()
there are all good. But when I use the exception of the
select() function to receive the out of band data from
the client PC, I use recv(__,__,MSG_OOB) to read out the
out of band data over, and then the exception still there.
I donot know why.
   My main question is:
    (1) How to clear the exception condition of select()
function, after read out the out of band data ?
    (2) I know the socket urgent data could use the signal
"SIGURG" and "SIGIO", but the exception of select() seems
the same or not ?

The Best Regards,
0
arthurjj
Asked:
arthurjj
1 Solution
 
julio011597Commented:
Hello arthurjj,

1) to clear the exception condition you will go as you probably do with read or write conditions: between select() calls, you should issue:

FD_CLR(file_descriptor, exception_set); /* which clears file_descriptor in exception_set */

or

FD_ZERO(exception_set) /* which clears the whole exception set */

2) SIGURG is raised when there's an urgent condition on a I/O channel (out-of-band data), while SIGIO is raised when _any_ kind of I/O is 'possible or completed';

SIGIO traps too many events to be useful for socket programming; SIGURG may be a way to know there's some oob data to read, but, unless your server application handles just one socket stream, you will still need to select();

so, in the end, select() remains the most common (maybe best general) way to check the state of one or more socket streams; you will usually go with signal handling just for a few particular tasks.

HTH, julio
0
 
arthurjjAuthor Commented:
Dear Sir:
   I received your answer about the exception of select() function. I tried it again, and found the result was the same
with before the exception still happened. My flow as following:
 In Sun Host:
  (0) Init all and listen.
  (1) Got a file description of socket connection--- fd1;
  (2) FD_ZERO(&fd_read); FD_ZERO(&fd_write); FD_ZERO(&fd_exc);
      FD_SET(fd1,&fd_read);FD_SET(fd1,&fd_write);
      FD_SET(fd1,&fd_exc);
  (3) ns=select(FD_SETSIZE,&fd_read,&fd_write,&fd_exc,&timeout);
  (4) if (ns==0) Goto Step (2);
      else if (ns<0) Goto Step_Error;
      else next;
  (5) if (FD_ISSET(fd1,&fd_read))  recv() all of input data;
  (6) if (FD_ISSET(fd1,&fd_write)) send() all of output data;
  (7) if (FD_ISSET(fd1,&fd_exc))   recv(,,MSG_OOB) all of
      out of band data. and use FD_CLR(fd1,&fd_exc);
  (8) Goto Step (2);
 
  While all the data and OOB data was read over. The IO buffer
  is empty. I use the ioctl(fd1,SIOCATMARK,&n1) to check it is
  really empty. The read and write flag were nothing but the
  exception flag( fd_exc) still exist.
  I do not know why ?
  Whould you solve this problem, please ?
  Thanks again !!!
  The Best Regards,
  Arthur Chang.
  arthurjj@ms5.hinet.net

 

 
       



0
 
lemontelCommented:
The problem is that select indicates an exception condition until the process reads beyond the out-of-band data(pp.530-531 of TCPv2).
The solution is to select for an exception condition only after reading normal data.
  -- UNIX Network Programming, Vol1, W.Richard Stevens
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now