[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] O_NONBLOCK and select/epoll/libevent
On Mon, Oct 26, 2009 at 09:32:00PM -0700, Evan Klitzke wrote:
> Hi all,
>
> Is there any reason to set a socket as non-blocking using
> fcntl/O_NONBLOCK before adding it to the libevent event loop?
I believe you may have the causality backwards here: most applications
that do this aren't using O_NONBLOCK because they want to use select()
[or poll(), or Libevent]. Instead, they are using O_NONBLOCK so that
they can handle many IO on sockets from a single thread without
blocking on IO operations, and they are using select() [or poll(), or
Libevent] so they can efficiently tell which sockets are ready to read
or write more.
In addition to the link that Springande Ulv posted, you should
definitely check out the (unfinished, but not too bad) Chapter 1 of
http://www.wangafu.net/~nickm/libevent-book/
This chapter tries to walk you through a series of examples about why
you might want to use nonblocking IO, and why (having chosen to use
nonblocking IO) you would need to use select() or poll() or epoll() or
kqueue() or Libevent.
[For the record, nothing in the Libevent event loop cares whether the
sockets you add are nonblocking or not.]
Hope this helps,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.