ioctl, FIONREAD and I_NREAD

  • Follow


Hello,

Does anybody knows something about FIONREAD and I_NREAD ioctl functions 
on Solaris ?

It seems that, once a select has selected a socket for read, it might be 
some latency before FIONREAD of I_NREAD to return something else than 0.

It seems also that I_NREAD, in such cases, might return 0 for the number 
of bytes to read, but something >0 for the number of messages in the queue.

I have not found anything regarding these behaviours in the Sun 
documentation not in the group archive.

Does anybody has some link or hint about that ?

Many thanks for any help,
-- 
Arnaud
(Supprimez les geneurs pour me r�pondre)

0
Reply Arnaud 4/1/2004 1:01:23 PM

In article <406c12a3$0$9122$626a14ce@news.free.fr>,
	Arnaud Meurgues <arnaud@meurgues.non.fr.invalid> writes:
> Hello,
> 
> Does anybody knows something about FIONREAD and I_NREAD ioctl functions 
> on Solaris ?
> 
> It seems that, once a select has selected a socket for read, it might be 
> some latency before FIONREAD of I_NREAD to return something else than 0.
> 
> It seems also that I_NREAD, in such cases, might return 0 for the number 
> of bytes to read, but something >0 for the number of messages in the queue.
> 
> I have not found anything regarding these behaviours in the Sun 
> documentation not in the group archive.

The man page for I_NREAD (streamio(7I)) explains exactly this situation...

     I_NREAD
           Counts the number of data bytes in data blocks in  the
           first  message  on  the  STREAM  head  read queue, and
           places this value in the location pointed to  by  arg.
           The return value for the command is the number of mes-
           sages on the STREAM head read queue. For  example,  if
           zero is returned in arg, but the ioctl return value is
           greater than zero, this indicates that  a  zero-length
           message is next on the queue.

Generally, if you want to know if there is any data, you should
check for number of bytes > 0 or return value > 0.

           /* check stream-head for data I haven't yet read */
           length = 0;
           i = ioctl(pccdata->fdin, I_NREAD, &length, sizeof(length));
           if (i > 0 || (i == 0 && length > 0))
                goto read_data;

Of course, it's possible there are only messages queued with no
bytes in them, so you'll need to allow for that case too.

-- 
Andrew Gabriel
0
Reply andrew 4/1/2004 1:55:39 PM


Andrew Gabriel wrote:

> The man page for I_NREAD (streamio(7I)) explains exactly this situation...

Yes, but what about FIONREAD ?

More precisely, I would like to understand the following code and the 
comments attached, extracted from the comm-socket.c of the proxy suite 
available there:
http://www.suse.de/~mt/proxy-suite/

static int  socket_ll_FIONREAD(HLS *hls, int *len)
{
         int ret;

         errno=0;
         ret=ioctl(hls->sock, FIONREAD, len);
#if defined(COMPILE_DEBUG)
         debug(4, "ll_FIONREAD: ret=%d, len=%d for %s %d=%s",
                  ret, *len, hls->ctyp, hls->sock, hls->peer);
#endif
         if(0 > ret) {
#if defined(__sun__)
                 /*
                 ** we are running on solaris - wait a little bit...
                 */
                 if(0 == *len && 0 == errno && (++hls->retr < 
MAX_RETRIES)) {
                         syslog_write(T_DBG,
                         "can't get num of bytes: %s %d=%s - retry %d",
                                             hls->ctyp, hls->sock,
                                             hls->peer, hls->retr);
                         usleep(10000);
                         return 1; /* retry */
                 }
#endif
                 syslog_error("can't get num of bytes: %s %d=%s",
                              hls->ctyp, hls->sock, hls->peer);
                 hls->ernr = errno;
                 close(hls->sock);
                 hls->sock = -1;
                 return -1;
         }
         return ret;
}

I am wondering what is the meaning of the comment: "we are running on 
solaris - wait a little bit..." for this part of code specific to Solaris.


>      I_NREAD
>            Counts the number of data bytes in data blocks in  the
>            first  message  on  the  STREAM  head  read queue, and
>            places this value in the location pointed to  by  arg.
>            The return value for the command is the number of mes-
>            sages on the STREAM head read queue. For  example,  if
>            zero is returned in arg, but the ioctl return value is
>            greater than zero, this indicates that  a  zero-length
>            message is next on the queue.

I don't understand what a "message" is supposed to be on a TCP socket.

-- 
Arnaud
(Supprimez les geneurs pour me r�pondre)

0
Reply Arnaud 4/1/2004 2:26:15 PM

2 Replies
590 Views

(page loaded in 0.382 seconds)

Similiar Articles:





7/23/2012 7:59:27 AM


Reply: