evutils.h 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #ifndef __EVUTILS_H__
  2. #define __EVUTILS_H__
  3. extern "C" {
  4. #include <event2/listener.h>
  5. #include <event2/bufferevent.h>
  6. }
  7. unsigned int hostlookup(const char *hostname);
  8. // Create a new listener socket. bindport is the port to bind to (in
  9. // host byte order), or 0 if any port will do. ip and boundport are set
  10. // to the IP and port of the socket, in network byte order.
  11. struct evconnlistener *listener_create(struct event_base *evbase,
  12. unsigned short bindport, evconnlistener_cb cb, void *ctx,
  13. unsigned int *ip, unsigned short *boundport);
  14. // Create a client connection to the given 6-byte ipport (4 byte IP, 2
  15. // byte port in network byte order).
  16. struct bufferevent *client_create(struct event_base *evbase,
  17. unsigned char ipport[6], bufferevent_event_cb event_handler);
  18. // Create a client connection to a controller, with event_handler set as
  19. // the event callback. It will be called when the connection succeeds or
  20. // fails. This function calls the libevent main loop, so it will only return
  21. // when the program is finished.
  22. int controller_client(const char *controller_host,
  23. unsigned short controller_port, bufferevent_event_cb event_handler);
  24. #endif