Statistics
| Revision:

root / src / socket.h @ 1

History | View | Annotate | Download (3.35 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2003 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 <netdb.h>
29

    
30
typedef struct _SockInfo        SockInfo;
31

    
32
#if USE_SSL
33
#  include "ssl.h"
34
#endif
35

    
36
typedef enum
37
{
38
        CONN_READY,
39
        CONN_LOOKUPSUCCESS,
40
        CONN_ESTABLISHED,
41
        CONN_LOOKUPFAILED,
42
        CONN_FAILED
43
} ConnectionState;
44

    
45
typedef gint (*SockConnectFunc)                (SockInfo        *sock,
46
                                         gpointer         data);
47
typedef gboolean (*SockFunc)                (SockInfo        *sock,
48
                                         GIOCondition         condition,
49
                                         gpointer         data);
50

    
51
struct _SockInfo
52
{
53
        gint sock;
54
#if USE_SSL
55
        SSL *ssl;
56
#endif
57
        GIOChannel *sock_ch;
58

    
59
        gchar *hostname;
60
        gushort port;
61
        ConnectionState state;
62
        gpointer data;
63

    
64
        SockFunc callback;
65
        GIOCondition condition;
66
};
67

    
68
gint sock_set_io_timeout                (guint sec);
69

    
70
gint sock_set_nonblocking_mode                (SockInfo *sock, gboolean nonblock);
71
gboolean sock_is_nonblocking_mode        (SockInfo *sock);
72

    
73
guint sock_add_watch                        (SockInfo *sock, GIOCondition condition,
74
                                         SockFunc func, gpointer data);
75

    
76
struct hostent *my_gethostbyname        (const gchar *hostname);
77

    
78
SockInfo *sock_connect                        (const gchar *hostname, gushort port);
79
gint sock_connect_async                        (const gchar *hostname, gushort port,
80
                                         SockConnectFunc func, gpointer data);
81
gint sock_connect_async_cancel                (gint id);
82

    
83
/* Basic I/O functions */
84
gint sock_printf        (SockInfo *sock, const gchar *format, ...)
85
                         G_GNUC_PRINTF(2, 3);
86
gint sock_read                (SockInfo *sock, gchar *buf, gint len);
87
gint sock_write                (SockInfo *sock, const gchar *buf, gint len);
88
gint sock_write_all        (SockInfo *sock, const gchar *buf, gint len);
89
gint sock_gets                (SockInfo *sock, gchar *buf, gint len);
90
gchar *sock_getline        (SockInfo *sock);
91
gint sock_puts                (SockInfo *sock, const gchar *buf);
92
gint sock_peek                (SockInfo *sock, gchar *buf, gint len);
93
gint sock_close                (SockInfo *sock);
94

    
95
/* Functions to directly work on FD.  They are needed for pipes */
96
gint fd_connect_unix        (const gchar *path);
97
gint fd_open_unix        (const gchar *path);
98
gint fd_accept                (gint sock);
99

    
100
gint fd_read                (gint sock, gchar *buf, gint len);
101
gint fd_write                (gint sock, const gchar *buf, gint len);
102
gint fd_write_all        (gint sock, const gchar *buf, gint len);
103
gint fd_gets                (gint sock, gchar *buf, gint len);
104
gchar *fd_getline        (gint sock);
105
gint fd_close                (gint sock);
106

    
107
/* Functions for SSL */
108
#if USE_SSL
109
gint ssl_read                (SSL *ssl, gchar *buf, gint len);
110
gint ssl_write                (SSL *ssl, const gchar *buf, gint len);
111
gint ssl_write_all        (SSL *ssl, const gchar *buf, gint len);
112
gint ssl_gets                (SSL *ssl, gchar *buf, gint len);
113
gchar *ssl_getline        (SSL *ssl);
114
gint ssl_peek                (SSL *ssl, gchar *buf, gint len);
115
#endif
116

    
117
#endif /* __SOCKET_H__ */