forked from pen-lang/pen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tcp.pen
29 lines (24 loc) · 916 Bytes
/
Tcp.pen
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
import 'Context'context { Context }
import 'Tcp'AcceptedStream { AcceptedStream }
import 'Tcp'Listener { Listener }
import 'Tcp'Stream { Stream }
# Create a listener bound to a server address.
Bind = \(ctx Context, address string) Listener | error {
context'Inner(ctx).TcpBind(address)
}
# Create a stream connected to a peer address.
Connect = \(ctx Context, address string) Stream | error {
context'Inner(ctx).TcpConnect(address)
}
# Accept a client connection and create its stream.
Accept = \(ctx Context, l Listener) AcceptedStream | error {
context'Inner(ctx).TcpAccept(l)
}
# Receive data from a peer through a stream with a size limit in bytes.
Receive = \(ctx Context, s Stream, limit number) string | error {
context'Inner(ctx).TcpReceive(s, limit)
}
# Send data to a peer through a stream.
Send = \(ctx Context, s Stream, data string) number | error {
context'Inner(ctx).TcpSend(s, data)
}