Solved

the exception of select()

Posted on 1997-05-25
3
281 Views
Last Modified: 2013-12-26
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
Comment
Question by:arthurjj
3 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 50 total points
ID: 1293097
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
 

Author Comment

by:arthurjj
ID: 1293098
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
 

Expert Comment

by:lemontel
ID: 7486536
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 81
Generic progress indicator 6 117
countEvens challenge 2 111
MaxSpan challenge 9 105
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question