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
|
/* 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_ADDRESS_H
#define MW_SOCKET_ADDRESS_H
#include <milkway/mw-socket-family.h>
#include <milkway/mw-object.h>
#include <milkway/mw-error.h>
typedef struct _mw_socket_address_type mw_socket_address_type_t;
typedef struct _mw_socket_address mw_socket_address_t;
typedef struct _mw_socket_address_priv mw_socket_address_priv_t;
#define MW_SOCKET_ADDRESS_TYPE mw_socket_address_get_type()
struct _mw_socket_address_type {
mw_object_type_t base;
mw_socket_family_t
(*get_family)(mw_socket_address_t *self);
size_t
(*get_native_size)(mw_socket_address_t *self);
mw_bool_t
(*to_native)(mw_socket_address_t *self,
void *native,
size_t size,
mw_error_t **reterr);
};
struct _mw_socket_address {
mw_object_t base;
mw_socket_address_priv_t *priv;
};
mw_public mw_socket_address_type_t*
mw_socket_address_get_type(void);
mw_public mw_socket_address_t*
mw_socket_address_init(mw_socket_address_t *self);
mw_public mw_socket_address_t*
mw_socket_address_new(void *addr,
size_t size);
static mw_inline mw_socket_family_t
mw_socket_address_get_family(mw_socket_address_t *self)
{
mw_socket_address_type_t *type = (mw_socket_address_type_t *)MW_TYPE(self);
return type->get_family(self);
}
static mw_inline size_t
mw_socket_address_get_native_size(mw_socket_address_t *self)
{
mw_socket_address_type_t *type = (mw_socket_address_type_t *)MW_TYPE(self);
return type->get_native_size(self);
}
static mw_inline mw_bool_t
mw_socket_address_to_native(mw_socket_address_t *self,
void *native,
size_t size,
mw_error_t **reterr)
{
mw_socket_address_type_t *type = (mw_socket_address_type_t *)MW_TYPE(self);
return type->to_native(self, native, size, reterr);
}
#endif
|