2006-07-25 [colin] 2.3.1cvs85
[claws.git] / src / common / socket.h
index 2660cdaf75dc73ad6d0ca7d5f2f27736173c5e97..de655e80b38fca6dcf5803e5eb57aa44e4ba5584 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifndef __SOCKET_H__
@@ -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,45 @@ 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;
 };
 
+void refresh_resolvers                 (void);
+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);
@@ -77,6 +89,7 @@ gint sock_connect_async                       (const gchar *hostname, gushort port,
                                         SockConnectFunc func, gpointer data);
 gint sock_connect_async_cancel         (gint id);
 
+/* 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);