Imported version 1.0
[claws.git] / src / socket.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __SOCKET_H__
21 #define __SOCKET_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28
29 #if USE_THREADS
30 #  include <pthread.h>
31 #endif
32
33 typedef struct _SockInfo        SockInfo;
34
35 typedef enum
36 {
37         CONN_READY,
38         CONN_LOOKUPSUCCESS,
39         CONN_ESTABLISHED,
40         CONN_LOOKUPFAILED,
41         CONN_FAILED
42 } ConnectionState;
43
44 struct _SockInfo
45 {
46         gint sock;
47         gchar *hostname;
48         gushort port;
49         ConnectionState state;
50         gpointer data;
51 #if USE_THREADS
52         pthread_t connect_thr;
53         pthread_mutex_t mutex;
54 #endif
55 };
56
57 gint sock_set_nonblocking_mode          (gint sock, gboolean nonblock);
58 gboolean sock_is_nonblocking_mode       (gint sock);
59
60 SockInfo *sock_connect_nb               (const gchar *hostname, gushort port);
61 SockInfo *sock_connect                  (const gchar *hostname, gushort port);
62
63 gint sock_connect_unix  (const gchar *path);
64 gint sock_open_unix     (const gchar *path);
65 gint sock_accept        (gint sock);
66
67 #if USE_THREADS
68 SockInfo *sock_connect_with_thread      (const gchar *hostname, gushort port);
69 #endif
70
71 void sock_sockinfo_free (SockInfo *sockinfo);
72
73 gint sock_printf        (gint sock, const gchar *format, ...)
74                          G_GNUC_PRINTF(2, 3);
75 gint sock_write         (gint sock, const gchar *buf, gint len);
76 gint sock_read          (gint sock, gchar *buf, gint len);
77 gint sock_puts          (gint sock, const gchar *buf);
78 gint sock_close         (gint sock);
79
80 #endif /* __SOCKET_H__ */