All of lore.kernel.org
 help / color / mirror / Atom feed
* TCP partial write
@ 2009-06-14 19:52 Paul Martin
  2009-06-15 17:09 ` Rick Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Martin @ 2009-06-14 19:52 UTC (permalink / raw)
  To: netdev

Is it possible that a (non-blocking) TCP write(2) will write a number
of bytes not multiple of the machine word size? i.e., could a write
request for 4 bytes return 2?

Also is this an OS-dependent behavior or there is a spec for it? (I
could find atomic guarantees for pipes and datagram sockets but not
for TCP)

Thanks,
Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TCP partial write
  2009-06-14 19:52 TCP partial write Paul Martin
@ 2009-06-15 17:09 ` Rick Jones
  2009-06-15 17:26   ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Rick Jones @ 2009-06-15 17:09 UTC (permalink / raw)
  To: Paul Martin; +Cc: netdev

Paul Martin wrote:
> Is it possible that a (non-blocking) TCP write(2) will write a number
> of bytes not multiple of the machine word size? i.e., could a write
> request for 4 bytes return 2?

Yes.

> Also is this an OS-dependent behavior or there is a spec for it? (I
> could find atomic guarantees for pipes and datagram sockets but not
> for TCP)

TCP is a byte-stream. It sends and receives a stream of bytes.  You should/must 
assume that when you do a non-blocking write, it will take any number of the 
bytes you offer from 0 to however many bytes you give it.  And you should/must 
assume that at the other end, your recv/read calls will return with between 0 and 
however many bytes you ask of them, with 0 meaning the remote has said it has 
nothing left to give.

rick jones

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TCP partial write
  2009-06-15 17:09 ` Rick Jones
@ 2009-06-15 17:26   ` Stephen Hemminger
  2009-06-15 17:59     ` Rick Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2009-06-15 17:26 UTC (permalink / raw)
  To: Rick Jones; +Cc: Paul Martin, netdev

On Mon, 15 Jun 2009 10:09:29 -0700
Rick Jones <rick.jones2@hp.com> wrote:

> Paul Martin wrote:
> > Is it possible that a (non-blocking) TCP write(2) will write a number
> > of bytes not multiple of the machine word size? i.e., could a write
> > request for 4 bytes return 2?
> 
> Yes.
> 
> > Also is this an OS-dependent behavior or there is a spec for it? (I
> > could find atomic guarantees for pipes and datagram sockets but not
> > for TCP)
> 
> TCP is a byte-stream. It sends and receives a stream of bytes.  You should/must 
> assume that when you do a non-blocking write, it will take any number of the 
> bytes you offer from 0 to however many bytes you give it.  And you should/must 
> assume that at the other end, your recv/read calls will return with between 0 and 
> however many bytes you ask of them, with 0 meaning the remote has said it has 
> nothing left to give.
> 

Actually on a blocking socket 0 means other end has closed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TCP partial write
  2009-06-15 17:26   ` Stephen Hemminger
@ 2009-06-15 17:59     ` Rick Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Rick Jones @ 2009-06-15 17:59 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Paul Martin, netdev

Stephen Hemminger wrote:
> On Mon, 15 Jun 2009 10:09:29 -0700
> Rick Jones <rick.jones2@hp.com> wrote:

>> And you should/must assume that at the other end, your recv/read calls will
>> return with between 0 and however many bytes you ask of them, with 0 meaning
>> the remote has said it has nothing left to give.
>>
> 
> 
> Actually on a blocking socket 0 means other end has closed.

Overly poetic wording on my part, using "said it has nothing left to give" to 
mean "other end has closed" :)

rick jones

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-06-15 17:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-14 19:52 TCP partial write Paul Martin
2009-06-15 17:09 ` Rick Jones
2009-06-15 17:26   ` Stephen Hemminger
2009-06-15 17:59     ` Rick Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.