Connection
on new connectionslibevent :: ConnectionListener :: base
Get theNativeEventBase
associated to self
libevent $ ConnectionListener :: SELF
Type of this instance, automatically specialized in every classcore :: Pointer :: address_is_null
Is the address behind this Object at NULL?libevent :: ConnectionListener :: base
Get theNativeEventBase
associated to self
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Pointer :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# A listener acting on an interface and port, spawns `Connection` on new connections
extern class ConnectionListener `{ struct evconnlistener * `}
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;
`}
private new bind_unix(base: NativeEventBase, file: CString, factory: ConnectionFactory)
import ConnectionFactory.accept_connection, error_callback `{
ConnectionFactory_incr_ref(factory);
struct sockaddr_un sun = {0};
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, file, sizeof(sun.sun_path) - 1);
struct evconnlistener *listener = evconnlistener_new_bind(base,
(evconnlistener_cb)accept_connection_cb, factory,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, -1,
(struct sockaddr*)&sun, sizeof(sun));
if (listener != NULL) {
evconnlistener_set_error_cb(listener,
(evconnlistener_errorcb)ConnectionListener_error_callback);
}
return listener;
`}
# Get the `NativeEventBase` associated to `self`
fun base: NativeEventBase `{ return evconnlistener_get_base(self); `}
# Callback on listening error
fun error_callback
do
var cstr = evutil_socket_error_to_string(evutil_socket_error)
print_error "libevent error: {cstr}"
end
end
lib/libevent/libevent.nit:419,1--479,3