[haiku-development] Re: server connection

  • From: Rene Gollent <anevilyak@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 23 Nov 2010 14:49:00 -0500

On Tue, Nov 23, 2010 at 2:43 PM, Clemens Zeidler
<clemens.zeidler@xxxxxxxxxxxxxx> wrote:

> whats happen if there are 3 bytes in the queue and I try to read 4 will recv
> return earlier?
> anyway thanks to both of you for all the input will try it out now :-)
>

recv() returns the number of bytes actually read, the passed in buffer
only limits the upper bound of how much it will read. If 3 bytes are
what's available when you call recv(), it will return immediately
having given you those 3 bytes. It only blocks if no data is currently
available at all (and the socket isn't in non-blocking mode)

> I'm unsure about this too can I write to the same socket id (from a second
> thread) while a recv is blocking? or do I have to create a second socket? if
> yes how?, can I clone it somehow?

Writing to the same socket from multiple threads is perfectly valid,
as with any other file descriptor.

Regards,

Rene

Other related posts: