139
|
1 #{
|
145
|
2 includeSystemHeader: "sys/types.h"
|
|
3 includeSystemHeader: "sys/socket.h"
|
|
4 includeSystemHeader: "netdb.h"
|
|
5
|
139
|
6 llMessage: AF_INET withVars: {
|
|
7 intret <- obj_int32 ptr
|
|
8 } andCode: {
|
|
9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
10 intret num!: AF_INET
|
|
11 intret
|
|
12 }
|
|
13 llMessage: AF_UNIX withVars: {
|
|
14 intret <- obj_int32 ptr
|
|
15 } andCode: {
|
|
16 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
17 intret num!: AF_UNIX
|
|
18 intret
|
|
19 }
|
|
20 llMessage: STREAM withVars: {
|
|
21 intret <- obj_int32 ptr
|
|
22 } andCode: {
|
|
23 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
24 intret num!: SOCK_STREAM
|
|
25 intret
|
|
26 }
|
|
27 llMessage: DGRAM withVars: {
|
|
28 intret <- obj_int32 ptr
|
|
29 } andCode: {
|
|
30 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
31 intret num!: SOCK_DGRAM
|
|
32 intret
|
|
33 }
|
|
34 llMessage: socket withVars: {
|
|
35 fd <- obj_int32 ptr
|
|
36 domain <- obj_int32 ptr
|
|
37 type <- obj_int32 ptr
|
|
38 protocol <- obj_int32 ptr
|
|
39 } andCode: :domain type protocol {
|
|
40 fd <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
41 fd num!: (socket: (domain num) (type num) (protocol num))
|
|
42 fd
|
|
43 }
|
145
|
44
|
139
|
45 new <- :domain type protocol {
|
|
46 sfd <- socket: domain type protocol
|
|
47 #{
|
|
48 fd <- {sfd}
|
|
49 llMessage: close withVars: {
|
|
50 sfd <- obj_int32 ptr
|
|
51 } andCode: {
|
|
52 sfd <- mcall: fd 1 self
|
|
53 close: (sfd num)
|
|
54 self
|
|
55 }
|
145
|
56 llMessage: send:withFlags withVars: {
|
|
57 odata <- object ptr
|
|
58 flags <- obj_int32 ptr
|
|
59 sdata <- string ptr
|
|
60 sfd <- obj_int32 ptr
|
|
61 res <- obj_int32 ptr
|
|
62 } andCode: :odata :flags {
|
|
63 sdata <- mcall: string 1 odata
|
|
64 sfd <- mcall: fd 1 self
|
|
65 res <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
66 res num!: (send: (sfd num) (sdata data) (sdata bytes) (flags num))
|
|
67 res
|
|
68 }
|
|
69 send <- :data {
|
|
70 send: data withFlags: 0
|
|
71 }
|
139
|
72 }
|
|
73 }
|
145
|
74
|
|
75 llMessage: _connectTo:onPort withVars: {
|
|
76 host <- string ptr
|
|
77 port <- string ptr
|
|
78 hints <- struct: addrinfo
|
|
79 info <- (struct: addrinfo) ptr
|
|
80 domain <- obj_int32 ptr
|
|
81 type <- obj_int32 ptr
|
|
82 protocol <- obj_int32 ptr
|
|
83 sock <- object ptr
|
|
84 sfd <- obj_int32 ptr
|
|
85 } andCode: :host :port {
|
|
86 memset: (addr_of: hints) 0 (sizeof: hints)
|
|
87 hints ai_family!: AF_UNSPEC
|
|
88 hints ai_socktype!: SOCK_STREAM
|
|
89 getaddrinfo: (host data) (port data) (addr_of: hints) (addr_of: info)
|
|
90
|
|
91 domain <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
92 domain num!: (info ai_family)
|
|
93 type <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
94 type num!: (info ai_socktype)
|
|
95 protocol <- make_object: (addr_of: obj_int32_meta) NULL 0
|
|
96 protocol num!: (info ai_protocol)
|
|
97
|
|
98 sock <- mcall: new 4 self domain type protocol
|
|
99 sfd <- mcall: fd 1 sock
|
|
100
|
|
101 connect: (sfd num) (info ai_addr) (info ai_addrlen)
|
|
102
|
|
103 freeaddrinfo: info
|
|
104 sock
|
|
105 }
|
|
106
|
139
|
107 connectTo:onPort <- :host :port {
|
145
|
108 _connectTo: host onPort: (string: port)
|
139
|
109 }
|
145
|
110 listenOn <- :port {
|
139
|
111 }
|
|
112 listenAt:onPort <- :host :port {
|
|
113 }
|
|
114 }
|