Return Receipt
[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 #include <gdk/gdk.h> /* ugly, just needed for the GdkInputCondition et al. */
29
30 #if USE_THREADS
31 #  include <pthread.h>
32 #endif
33
34 typedef struct _SockInfo        SockInfo;
35
36 typedef enum
37 {
38         CONN_READY,
39         CONN_LOOKUPSUCCESS,
40         CONN_ESTABLISHED,
41         CONN_LOOKUPFAILED,
42         CONN_FAILED
43 } ConnectionState;
44
45 struct _SockInfo
46 {
47 #if USE_GIO
48         GIOChannel *channel;
49         gchar *buf;
50         gint buflen;
51 #else
52         gint sock;
53 #endif
54         gchar *hostname;
55         gushort port;
56         ConnectionState state;
57         gpointer data;
58 #if USE_THREADS
59         pthread_t connect_thr;
60         pthread_mutex_t mutex;
61 #endif
62 };
63
64 gint sock_set_nonblocking_mode          (SockInfo *sock, gboolean nonblock);
65 gboolean sock_is_nonblocking_mode       (SockInfo *sock);
66
67 SockInfo *sock_connect_nb               (const gchar *hostname, gushort port);
68 SockInfo *sock_connect                  (const gchar *hostname, gushort port);
69
70
71 #if USE_THREADS
72 SockInfo *sock_connect_with_thread      (const gchar *hostname, gushort port);
73 #endif
74
75 gint sock_printf        (SockInfo *sock, const gchar *format, ...)
76                          G_GNUC_PRINTF(2, 3);
77 gint sock_read          (SockInfo *sock, gchar *buf, gint len);                  
78 gint sock_write         (SockInfo *sock, const gchar *buf, gint len);
79 gint sock_gets          (SockInfo *sock, gchar *buf, gint len);
80 gint sock_puts          (SockInfo *sock, const gchar *buf);
81 gint sock_close         (SockInfo *sock);
82
83 /* wrapper functions */
84 gint sock_gdk_input_add   (SockInfo             *sock,
85                            GdkInputCondition     condition,
86                            GdkInputFunction      function,
87                            gpointer              data);
88
89
90 /* Functions to directly work on FD.  They are needed for pipes */
91 gint fd_connect_unix    (const gchar *path);
92 gint fd_open_unix       (const gchar *path);
93 gint fd_accept          (gint sock);
94
95 gint fd_read            (gint sock, gchar *buf, gint len);
96 gint fd_write           (gint sock, const gchar *buf, gint len);
97 gint fd_close           (gint sock);
98
99 #endif /* __SOCKET_H__ */
100