aboutsummaryrefslogtreecommitdiff
path: root/types/socket.d.tl
diff options
context:
space:
mode:
Diffstat (limited to 'types/socket.d.tl')
-rw-r--r--types/socket.d.tl158
1 files changed, 158 insertions, 0 deletions
diff --git a/types/socket.d.tl b/types/socket.d.tl
new file mode 100644
index 00000000..e62e907b
--- /dev/null
+++ b/types/socket.d.tl
@@ -0,0 +1,158 @@
1local ltn12 = require("ltn12")
2local Sink = ltn12.Sink
3local Source = ltn12.Source
4
5local record socket
6 record TCP
7 -- master methods
8 bind: function(TCP, string, integer)
9 connect: function(TCP, string, integer): integer, string
10 listen: function(TCP, integer): integer, string
11
12 -- client methods
13 getpeername: function(TCP): string, integer
14
15 enum TCPReceivePattern
16 "*l"
17 "*a"
18 end
19 enum TCPReceiveError
20 "closed"
21 "timeout"
22 end
23 receive: function(TCP, TCPReceivePattern|integer, string): string, TCPReceiveError
24
25 send: function(TCP, string, integer, integer): integer, string, integer
26
27 enum TCPShutdownMode
28 "both"
29 "send"
30 "receive"
31 end
32 shutdown: function(TCP, TCPShutdownMode): integer
33
34 -- server methods
35 accept: function(TCP): TCP, string
36
37 -- client and server methods
38 enum TCPOption
39 "keepalive"
40 "reuseaddr"
41 "tcp-nodelay"
42 end
43 enum TCPLinger
44 "linger"
45 end
46 record TCPLingerOption
47 on: boolean
48 timeout: integer
49 end
50 setoption: function(TCP, TCPOption): integer
51 setoption: function(TCP, TCPLinger, TCPLingerOption): integer
52
53 -- master, client, and server methods
54 close: function(TCP)
55
56 getsockname: function(TCP): string, integer
57
58 getstats: function(TCP): integer, integer, integer
59
60 setstats: function(TCP, integer, integer, integer): integer
61
62 enum TCPTimeoutMode
63 "b"
64 "t"
65 end
66 settimeout: function(TCP, integer, TCPTimeoutMode)
67 end
68 record UDP
69 close: function(UDP)
70
71 getpeername: function(UDP): string, integer
72
73 getsockname: function(UDP): string, integer
74
75 enum UDPTimeout
76 "timeout"
77 end
78 receive: function(UDP, integer): string, UDPTimeout
79
80 receivefrom: function(UDP, integer): string, string, integer, UDPTimeout
81
82 send: function(UDP, string): integer, string
83
84 sendto: function(UDP, string, string, integer): integer, string
85
86 setpeername: function(UDP, string, integer): integer, string
87
88 setsockname: function(UDP, string, integer): integer, string
89
90 enum UDPOptions
91 "dontroute"
92 "broadcast"
93 end
94 setoption: function(UDP, UDPOptions, boolean): integer, string
95
96 settimeout: function(UDP, integer)
97 end
98 tcp: function(): TCP, string
99
100 udp: function(): UDP, string
101
102 record dns
103 record DNSResolved
104 name: string
105 alias: {string}
106 ip: {string}
107 end
108 toip: function(): string
109 tohostname: function(string): string, DNSResolved|string
110 gethostname: function(string): string, DNSResolved|string
111 end
112
113 bind: function(string, integer, integer): TCP
114
115 connect: function(string, integer, string, integer): TCP
116
117 _DEBUG: boolean
118
119 newtry: function(function): function
120
121 protect: function(function): function
122
123 -- tagged records/Table Union types would be nice here,
124 -- as this should be {TCP|UDP}
125 -- but I imagine this should be fine for most uses
126 select: function({UDP}, {UDP}, integer): {UDP}, {UDP}, string
127 select: function({TCP}, {TCP}, integer): {TCP}, {TCP}, string
128
129 enum SinkMode
130 "http-chunked"
131 "close-when-done"
132 "keep-open"
133 end
134
135 sink: function(SinkMode, UDP): Sink
136 sink: function(SinkMode, TCP): Sink
137
138 skip: function(integer, ...: any): any...
139
140 sleep: function(integer)
141
142 enum SourceMode
143 "http-chunked"
144 "by-length"
145 "until-closed"
146 end
147
148 source: function(SourceMode, TCP, integer): Source
149 source: function(SourceMode, UDP, integer): Source
150
151 gettime: function(): integer
152
153 try: function(...: any): any...
154
155 _VERSION: string
156end
157
158return socket \ No newline at end of file