1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* Milkway
*
* Copyright (C) 2008- Luo Jinghua <sunmoon1997@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef MW_SOCKET_H
#define MW_SOCKET_H
#include <milkway/mw-object.h>
#include <milkway/mw-socket-address.h>
#include <milkway/mw-net-types.h>
typedef struct _mw_socket__type mw_socket__type_t;
typedef struct _mw_socket mw_socket_t;
typedef struct _mw_socket_priv mw_socket_priv_t;
#define MW_SOCKET_TYPE mw_socket__get_type()
#define MW_ERROR_SOCKET "MWSocketError"
struct _mw_socket__type {
mw_object_type_t base;
};
struct _mw_socket {
mw_object_t base;
mw_socket_priv_t *priv;
};
mw_public mw_socket__type_t*
mw_socket__get_type(void);
mw_public mw_socket_t*
mw_socket_new(mw_socket_family_t family,
mw_socket_type_t type,
mw_socket_proto_t proto,
mw_error_t **reterr);
mw_public mw_socket_t*
mw_socket_new_from_fd(int fd,
mw_error_t **reterr);
mw_public int
mw_socket_get_fd(mw_socket_t *self);
mw_public mw_socket_family_t
mw_socket_get_family(mw_socket_t *self);
mw_public mw_socket_type_t
mw_socket_get_type(mw_socket_t *self);
mw_public mw_socket_proto_t
mw_socket_get_proto(mw_socket_t *self);
mw_public mw_bool_t
mw_socket_is_connected(mw_socket_t *self);
mw_public mw_bool_t
mw_socket_bind(mw_socket_t *self,
mw_socket_address_t *address,
mw_error_t **reterr);
mw_public mw_bool_t
mw_socket_listen(mw_socket_t *self,
int backlog,
mw_error_t **reterr);
mw_public mw_bool_t
mw_socket_connect(mw_socket_t *self,
mw_socket_address_t *address,
mw_error_t **reterr);
mw_public mw_socket_t*
mw_socket_accept(mw_socket_t *self,
mw_error_t **reterr);
mw_public int
mw_socket_recv(mw_socket_t *self,
void *buffer,
size_t size,
mw_error_t **reterrr);
mw_public int
mw_socket_send(mw_socket_t *self,
const void *buffer,
size_t size,
mw_error_t **reterrr);
mw_public mw_bool_t
mw_socket_shutdown(mw_socket_t *self,
mw_bool_t read,
mw_bool_t write,
mw_error_t **reterr);
mw_public mw_bool_t
mw_socket_close(mw_socket_t *self,
mw_error_t **reterr);
#endif
|