-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSocket.clcl
219 lines (170 loc) · 5.67 KB
/
Socket.clcl
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
class sockaddr
{
include MObjectBase;
sa_family: int;
sa_data: String;
def initialize() {
}
def clone():sockaddr {
result := sockaddr();
result.sa_family = self.sa_family;
if(self.sa_data.identifyWith(null).negative()) {
result.sa_data = self.sa_data.clone();
}
return result;
}
}
class sockaddr_un
{
include MObjectBase;
sun_family: int;
sun_path: String;
def initialize() {
}
def clone(): sockaddr_un {
result := sockaddr_un();
result.sun_family = self.sun_family;
if(self.sun_path.identifyWith(null).negative()) {
result.sun_path = self.sun_path.clone();
}
return result;
}
}
class in_addr
{
include MObjectBase;
typedef in_addr_t uint;
s_addr:in_addr_t;
def initialize() {}
def clone(): in_addr {
result := in_addr();
result.s_addr = self.s_addr;
return result;
}
}
class sockaddr_in
{
include MObjectBase;
sin_family: int;
sin_addr: in_addr;
sin_port: int;
def initialize() {
sin_addr = in_addr();
}
def clone(): sockaddr_in {
result := sockaddr_in();
result.sin_family = self.sin_family;
if(self.sin_addr.identifyWith(null).negative()) {
result.sin_addr = self.sin_addr.clone();
}
result.sin_port = self.sin_port;
return result;
}
}
class servent
{
include MObjectBase;
s_name:String;
s_aliases: String[];
s_port:int;
s_proto:String;
def initialize() {}
def clone(): servent {
result := servent();
if(!self.s_name.identifyWith(null)) {
result.s_name = self.s_name.clone();
}
if(!self.s_aliases.identifyWith(null)) {
result.s_aliases = String[self.s_aliases.length]();
for(i:=0; i<self.s_aliases.length; i++) {
result.s_aliases[i] = self.s_aliases[i].clone();
}
}
result.s_port = self.s_port;
if(!self.s_proto.identifyWith(null)) {
result.s_proto = self.s_proto.clone();
}
return result;
}
}
class hostent
{
include MObjectBase;
h_name:String;
h_aliases:String[];
h_addrtype:int;
h_length:int;
h_addr_list: String[];
def initialize() {}
def clone():hostent {
result := hostent();
if(!self.h_name.identifyWith(null)) {
result.h_name = self.h_name.clone();
}
if(self.h_aliases.identifyWith(null).negative()) {
result.h_aliases = String[self.h_aliases.length]();
for(i:=0; i<self.h_aliases.length; i++) {
result.h_aliases[i] = self.h_aliases[i].clone();
}
}
result.h_addrtype = self.h_addrtype;
result.h_length = self.h_length;
if(self.h_addr_list.identifyWith(null).negative()) {
result.h_addr_list = String[self.h_addr_list.length]();
for(i:=0; i<self.h_addr_list.length; i++) {
result.h_addr_list[i] = self.h_addr_list[i].clone();
}
}
return result;
}
}
inherit System
{
AF_UNIX:static int;
AF_LOCAL:static int;
AF_INET:static int;
AF_INET6:static int;
AF_IPX:static int;
AF_NETLINK:static int;
AF_X25:static int;
AF_AX25:static int;
AF_ATMPVC:static int;
AF_APPLETALK:static int;
AF_PACKET:static int;
AF_ALG:static int;
SOCK_STREAM:static int;
SOCK_DGRAM:static int;
SOCK_SEQPACKET:static int;
SOCK_RAW:static int;
SOCK_RDM:static int;
SOCK_PACKET:static int;
SOCK_NONBLOCK:static int;
SOCK_CLOEXEC:static int;
SOCK_STREAM:static int;
def initialize_socket_system(): static native;
def initialize():static {
inherit();
initialize_socket_system();
}
def socket(domain:int, type:int, protocol:int): native static int throws Exception;
def connect(sockfd:int, addr:sockaddr_un): native static throws Exception;
def connect(sockfd:int, addr:sockaddr_in): native static throws Exception;
def bind(sockfd:int, addr:sockaddr_un): native static throws Exception;
def bind(sockfd:int, addr:sockaddr_in): native static throws Exception;
def accept(sockfd:int, addr:sockaddr_un): native static int throws Exception;
def accept(sockfd:int, addr:sockaddr_in): native static int throws Exception;
def recv(sockfd:int, buf:Buffer, len:size_t, flags:int): native static ssize_t throws Exception;
def recvfrom(sockfd:int, buf:Buffer, len:size_t, flags:int, src_addr:sockaddr_un): native static ssize_t throws Exception;
def recvfrom(sockfd:int, buf:Buffer, len:size_t, flags:int, src_addr:sockaddr_in): native static ssize_t throws Exception;
def listen(sockfd:int, backlog:int): native static throws Exception;
def send(sockfd:int, buf:Buffer, size:size_t, flags:int):native static ssize_t throws Exception;
def sendto(sockfd:int, buf:Buffer, size:size_t, flags:int, dest_addr:sockaddr_un): native static ssize_t throws Exception;
def sendto(sockfd:int, buf:Buffer, size:size_t, flags:int, dest_addr:sockaddr_in): native static ssize_t throws Exception;
def inet_addr(cp:String):static native in_addr_t;
def gethostbyaddr(addr:pointer, len:size_t, type:int): static native hostent throws Exception;
def gethostbyname(name:String): static native hostent throws Exception;
def getservbyname(name:String, proto:String): static native servent throws Exception;
def getservbyport(port:int, proto:String): static native servent throws Exception;
def inet_ntoa(in:in_addr): static native String throws Exception;
def gethostname(): static native String;
}