2005-09-14 [paul] 1.9.14cvs26
[claws.git] / src / common / socket.h
index 0c46a82ee56e53e5fa84fab78b5743089672415c..75136fd159ec39e521607fee90173701920ddb22 100644 (file)
@@ -25,7 +25,9 @@
 #endif
 
 #include <glib.h>
-#include <netdb.h>
+#if HAVE_NETDB_H
+#  include <netdb.h>
+#endif
 
 typedef struct _SockInfo       SockInfo;
 
@@ -40,35 +42,55 @@ typedef enum
        CONN_ESTABLISHED,
        CONN_LOOKUPFAILED,
        CONN_FAILED,
-       CONN_DISCONNECTED,
+       CONN_DISCONNECTED
 } ConnectionState;
 
+typedef gint (*SockConnectFunc)                (SockInfo       *sock,
+                                        gpointer        data);
+typedef gboolean (*SockFunc)           (SockInfo       *sock,
+                                        GIOCondition    condition,
+                                        gpointer        data);
+
 struct _SockInfo
 {
-#if USE_GIO
-       GIOChannel *channel;
-       gchar *buf;
-       gint buflen;
-#else
        gint sock;
+#if USE_OPENSSL
+       SSL *ssl;
+       guint g_source;
 #endif
+       GIOChannel *sock_ch;
+
        gchar *hostname;
        gushort port;
        ConnectionState state;
        gpointer data;
-#if USE_OPENSSL
-       SSL *ssl;
-#endif
+
+       SockFunc callback;
+       GIOCondition condition;
 };
 
+gint sock_init                         (void);
+gint sock_cleanup                      (void);
+
+gint sock_set_io_timeout               (guint sec);
+
 gint sock_set_nonblocking_mode         (SockInfo *sock, gboolean nonblock);
 gboolean sock_is_nonblocking_mode      (SockInfo *sock);
 
+guint sock_add_watch                   (SockInfo *sock, GIOCondition condition,
+                                        SockFunc func, gpointer data);
+
 struct hostent *my_gethostbyname       (const gchar *hostname);
 
 SockInfo *sock_connect                 (const gchar *hostname, gushort port);
 SockInfo *sock_connect_cmd             (const gchar *hostname, const gchar *tunnelcmd);
+#ifdef G_OS_UNIX
+gint sock_connect_async                        (const gchar *hostname, gushort port,
+                                        SockConnectFunc func, gpointer data);
+gint sock_connect_async_cancel         (gint id);
+#endif
 
+/* Basic I/O functions */
 gint sock_printf       (SockInfo *sock, const gchar *format, ...)
                         G_GNUC_PRINTF(2, 3);
 gint sock_read         (SockInfo *sock, gchar *buf, gint len);
@@ -77,14 +99,9 @@ gint sock_write_all  (SockInfo *sock, const gchar *buf, gint len);
 gint sock_gets         (SockInfo *sock, gchar *buf, gint len);
 gchar *sock_getline    (SockInfo *sock);
 gint sock_puts         (SockInfo *sock, const gchar *buf);
+gint sock_peek         (SockInfo *sock, gchar *buf, gint len);
 gint sock_close                (SockInfo *sock);
 
-/* wrapper functions */
-gint sock_input_add      (SockInfo             *sock,
-                          GIOCondition          condition,
-                          GIOFunc               function,
-                          gpointer              data);
-
 /* Functions to directly work on FD.  They are needed for pipes */
 gint fd_connect_unix   (const gchar *path);
 gint fd_open_unix      (const gchar *path);
@@ -104,6 +121,7 @@ gint ssl_write              (SSL *ssl, const gchar *buf, gint len);
 gint ssl_write_all     (SSL *ssl, const gchar *buf, gint len);
 gint ssl_gets          (SSL *ssl, gchar *buf, gint len);
 gint ssl_getline       (SSL *ssl, gchar **str);
+gint ssl_peek          (SSL *ssl, gchar *buf, gint len);
 #endif
 
 #endif /* __SOCKET_H__ */