Re: Q about low lvl UNIX socket programming

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Fri Apr 28 2000 - 09:45:35 EST


On Fri, 28 Apr 2000, [ISO-8859-1] Jerry Lundström wrote:

> On Fri, 28 Apr 2000 17:50:39 +0530 (IST), <animesh_singh@bbv.satyam.com> wrote:
>
> >
> >Thats simple for eg::
> >while(data_to_recv){
> > // if ioctl returns -ve you are doomed
> > if(ioctl(sock_descriptor,TIOCINQ,(unsigned long)&available) < 0){
> > perror("ioctl");
> > break;
> > }
> > if(available > data_to_recv)
> > // this is last iteration but be careful
> > bytes_recv = recvmsg(sock_descriptor,&buffer,data_to_recv,0);
> > else
> > //this should give all the data available in sock pipe
> > bytes_recv = recvmsg(sock_descriptor,&buffer,available,0);
> >
> > data_to_recv = data_to_recv - bytes_recv;
> >}
> >with nonblocking sock recv will return immediatly with EAGAIGN if no data
> >is avaible so check for the presence of data in the sock pipe before
> >making any recv
>
> Well, the recv part is no problem, it was more the sending part I wanted
> to control more then just getting back how much was written.
>
> Ive solved it by using TIOCOUTQ to check how much is free in the sending
> buffer. The recv part is easy fixed with position checking since I have
> a set size of the message.

You had asked for a portable method. I stated that there was no portable
method. The information you received about ioctl(TIOCOUTQ) is an example
of a "method". However, like most ioctls, they are seldom portable. In
fact, if you try this on a Sun, you are in a world of trouble because
ioctl(fd,TIOCOUTQ), defined as (tIOC|115), will return a constant
representing the compiled-in queue-size. (SunOS 5.5.1).

Cheers,
Dick Johnson

Penguin : Linux version 2.3.41 on an i686 machine (800.63 BogoMips).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:15 EST