Re: Q about low lvl UNIX socket programming

From: James Sutherland (jas88@cam.ac.uk)
Date: Fri Apr 28 2000 - 10:37:05 EST


On Fri, 28 Apr 2000, Jerry Lundström wrote:
> On Fri, 28 Apr 2000 18:34:19 +0400 (MSK DST), kuznet@ms2.inr.ac.ru wrote:
>
> >Hello!
> >
> >> Ive solved it by using TIOCOUTQ to check how much is free in the sending
> >> buffer.
> >
> >TIOCOUTQ is undefined for sockets. "T" stands for terminal
> >and it returns amount of data _queued_ in tty, rather than available
> >for write. TIOCINQ is undefined for sockets as well, but it is alias
> >for FIONREAD.
> >
>
> Hmm, didn't know this, thanks.
>
> >Blocking sockets make no guarantees about blocking when
> >writing more than one byte and always may do partial writes.
> >Use non-blocking IO, if you do not want to block.
>
> Blocking or non-blocking, the write will still split it.

Any write is virtually certain to be split up at some level. For a network
write, it will be chopped into packets; for a disk write, it will be
chopped into FS clusters, then chopped up again into sectors. What,
exactly, are you trying to achieve? Do you have multiple threads writing
to one socket, and want to make sure they don't interrupt each other's
output? If so, I'd have thought a lock of some sort would be the solution,
surely?

James.

-
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