Example unix socket echo server

Alejandro Mery amery at geeks.cl
Tue Nov 2 12:15:29 CET 2010

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() ?

More information about the libev mailing list