*/
typedef void (*evconnlistener_cb)(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *);
+/**
+ A callback that we invoke when a listener encounters a non-retriable error.
+
+ @param listener The evconnlistener
+ @param user_arg the pointer passed to evconnlistener_new()
+ */
+typedef void (*evconnlistener_errorcb)(struct evconnlistener *, void *);
+
/** Flag: Indicates that we should not make incoming sockets nonblocking
* before passing them to the callback. */
#define LEV_OPT_LEAVE_SOCKETS_BLOCKING (1u<<0)
/** Return the socket that an evconnlistner is listening on. */
evutil_socket_t evconnlistener_get_fd(struct evconnlistener *lev);
+/** Set an evconnlistener's error callback. */
+void evconnlistener_set_error_cb(struct evconnlistener *lev,
+ evconnlistener_errorcb errorcb);
+
#ifdef __cplusplus
}
#endif
struct evconnlistener {
const struct evconnlistener_ops *ops;
evconnlistener_cb cb;
+ evconnlistener_errorcb errorcb;
void *user_data;
unsigned flags;
};
return event_get_base(&lev_e->listener);
}
+void evconnlistener_set_error_cb(struct evconnlistener *lev,
+ evconnlistener_errorcb errorcb)
+{
+ lev->errorcb = errorcb;
+}
+
static void
listener_read_cb(evutil_socket_t fd, short what, void *p)
{
err = evutil_socket_geterror(fd);
if (EVUTIL_ERR_ACCEPT_RETRIABLE(err))
return;
- event_sock_warn(fd, "Error from accept() call");
+ if (lev->errorcb != NULL)
+ lev->errorcb(lev, lev->user_data);
+ else
+ event_sock_warn(fd, "Error from accept() call");
}
#ifdef WIN32