src/sock.h
changeset 9 4c4c906cc649
parent 8 be88e543c8ff
child 10 9fe218576d13
--- a/src/sock.h	Sun Feb 22 08:21:22 2009 +0200
+++ b/src/sock.h	Sun Feb 22 08:48:21 2009 +0200
@@ -6,6 +6,7 @@
  */
 #include "error.h"
 #include <sys/types.h>
+#include <event2/event.h>
 
 /*
  * The generic socket handle
@@ -13,9 +14,22 @@
 struct sock_stream;
 
 /*
+ * Async callbacks for socket operation
+ */
+struct sock_stream_callbacks {
+    /* Sockeet is readable */
+    void (*on_read)(struct sock_stream *sock, void *arg);
+
+    /* Socket is writeable */
+    void (*on_write)(struct sock_stream *sock, void *arg);
+};
+
+/*
  * Initialize the socket module's global state. Call this before calling any other sock_* functions.
+ *
+ * The given \a ev_base is the libevent base to use for nonblocking operation.
  */
-err_t sock_init (struct error_info *err);
+err_t sock_init (struct event_base *ev_base, struct error_info *err);
 
 /*
  * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via
@@ -37,6 +51,11 @@
 err_t sock_gnutls_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);
 
 /*
+ * Set the callbacks for a sock_stream. Note that the callbacks struct isn't copied - it's used as-is-given.
+ */
+void sock_stream_set_callbacks (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg);
+
+/*
  * The generic read/write API for stream sockets.
  */
 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len);