Property definitions

libevent $ ConnectionListener :: defaultinit
# 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