[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] strange exit with hand-made socket and bufferevent
On Tue, Feb 16, 2010 at 2:57 PM, Mihai Draghicioiu
<mihai.draghicioiu@xxxxxxxxx> wrote:
> Thanks Brian! Indeed, if I put the two lines that enable writing and
> write to the bufferevent right in the connected callback, the darn
> thing works fine!
>
> However, this was just a minimal example. I'd like it, however, if
> libevent supported this by marking inside the bufferevent structure
> that the socket fd is connected or isn't connected, and only write to
> it when it has connected. I suspect libevent checks if the fd==-1, and
> only then issues the connect(). if fd!=-1, it assumes it's connected.
> So this would be simplified if libevent somehow knew about my fd, and
> whether it's connected or not... There seems to be a getpeername()
> function that might do the trick.
Hm. Right now, Libevent assumes that a socket is unconnected if you
call bufferevent_socket_connect() on it. The problem seems to have
been that bufferevent_socket_connect_hostname() didn't also suspend
reading and writing until the hostname resolution was done. I've
checked in a fix as db08f640; does that work for you? It makes your
original example work for me on Linux[1], but I haven't tried it on
your longer program.
[1] BTW, please remember to mention what version of Libevent, what
operating system, and what language you're using. The original
example code doesn't build for me in C (since you're casting to
"event_base" instead of "struct event_base"), and works fine on OSX
(by some weird OSX accident I didn't investigate).
yrs,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.