Solved

the exception of select()

Posted on 1997-05-25
3
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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