src/sock.h
changeset 3 cc94ae754e2a
parent 2 a834f0559939
child 4 a3ca0f97a075
--- a/src/sock.h	Sun Feb 22 05:27:29 2009 +0200
+++ b/src/sock.h	Sun Feb 22 06:44:16 2009 +0200
@@ -4,6 +4,7 @@
 /*
  * Low-level socket-related functions
  */
+#include "error.h"
 #include <sys/types.h>
 
 /*
@@ -12,14 +13,19 @@
 struct sock_stream;
 
 /*
- * A simple blocking TCP connect to the given host/service, using getaddrinfo.
+ * Initialize the socket module's global state. Call this before calling any other sock_* functions.
+ */
+err_t sock_init (void);
+
+/*
+ * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via
+ * *sock_ptr. In case of errors, additional error information is stored in *err
+ *
+ * @return zero on success, nonzero on error
  *
  * XXX: blocking
- * XXX: exits on error
- *
- * Returns the socket handle.
  */
-struct sock_stream *sock_tcp_connect (const char *host, const char *service);
+err_t sock_tcp_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);
 
 /*
  * A simple blocking SSL connect to the given host/service.
@@ -28,19 +34,19 @@
  * XXX: doesn't do any certificate verification.
  * XXX: exits on error
  *
- * Returns the socket handle.
+ * Returns the socket handle, or NULL on errors.
  */
 struct sock_stream *sock_ssl_connect (const char *host, const char *service);
 
 /*
- * Initialize the socket module's global state
- */
-void sock_init (void);
-
-/*
  * The generic read/write API for stream sockets.
  */
-int sock_stream_read (struct sock_stream *sock, void *buf, size_t len);
-int sock_stream_write (struct sock_stream *sock, const void *buf, size_t len);
+err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len);
+err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len);
+
+/**
+ * Get last err_info for \a sock, returned via \a *err.
+ */
+void sock_stream_error (struct sock_stream *sock, struct error_info *err);
 
 #endif