Solved

the exception of select()

Posted on 1997-05-25
3
244 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now