[OT] why send()/recv() instead of write()/read()

AJ ONeal coolaj86 at gmail.com
Tue Nov 2 21:14:42 CET 2010

I  don't know. That's just what the examples that I've been modeling after
have been using.

Here's what I was able to dig up in (literally) 6 seconds from the page I
was on:

Finally, you might be curious as to why I'm using *write()* and
*read()*instead of
*send()* and *recv()*. Well, in short, I was being lazy. See, by using these
system calls, I don't have to enter the *flags* argument that *send()* and *
recv()* use, and I always set it to zero anyway. Of course, socket
descriptors are just file descriptors like any other, so they respond just
fine to many file manipulation system calls.

AJ ONeal

On Tue, Nov 2, 2010 at 5:15 AM, Alejandro Mery <amery at geeks.cl> wrote:

> On Tue, Nov 2, 2010 at 08:41, Marc Lehmann <schmorp at schmorp.de> wrote:
> > On Mon, Nov 01, 2010 at 10:44:58PM -0600, AJ ONeal <coolaj86 at gmail.com>
> wrote:
> >> The question that I have is if it's true to say that a unix socket is
> >> writable whenever it is readable?
> >
> > No, a unix domain socket works mostly like other stream sockets.
> >
> >> When I tried listening for when it was writable, it seemed to fire the
> event
> >> over and over again.
> >
> > Do you have reason to assume that it was not writable over and over
> again?
> >
> > For it not to be writable you'd have to write enough data to fill it's
> > buffers, and make sure nobody is reading on the other side.
> >
> >> Or is it that when I want to send data I should
> >>     start the watcher for writes
> >>     send the data
> >>     stop the watcher
> >> ?
> >
> > If you mean your write watcher was always active, then this explains your
> > issue. Think about it, you ask libev when the socket is writable, but
> > don't write anything. This means the socket will stay writable - there is
> > no way for libev to know thta for some reason you are no longer
> interested
> > in writability, except by stopping the watcher.
> >
> > A common (not necessarily most efficient) way to handle writes is:
> >
> >   start the watcher
> >   in callback
> >      write more of the remaining data
> >      if all data has been written, stop the watcher
> kind of off-topic, but why send()/recv() instead of write()/read() ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20101102/3771ed5e/attachment.html>

More information about the libev mailing list