private new bind_tcp(base: NativeEventBase, address: CString, port: Int, factory: ConnectionFactory)
import ConnectionFactory.accept_connection, error_callback `{
ConnectionFactory_incr_ref(factory);
struct hostent *hostent = gethostbyname(address);
if (!hostent) {
return NULL;
}
struct sockaddr_in sin = {0};
sin.sin_family = hostent->h_addrtype;
sin.sin_port = htons(port);
memcpy( &(sin.sin_addr.s_addr), (const void*)hostent->h_addr, hostent->h_length );
struct evconnlistener *listener = evconnlistener_new_bind(base,
(evconnlistener_cb)accept_connection_cb, factory,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, -1,
(struct sockaddr*)&sin, sizeof(sin));
if (listener != NULL) {
evconnlistener_set_error_cb(listener,
(evconnlistener_errorcb)ConnectionListener_error_callback);
}
return listener;
`}
lib/libevent/libevent.nit:422,2--447,3