aboutsummaryrefslogtreecommitdiff
path: root/types/socket.d.tl
blob: f450503bbf30f000a17eb3f169e492c7ad665432 (plain)
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
local ltn12 = require("ltn12")
local type Sink = ltn12.Sink
local type Source = ltn12.Source

local record socket
   record TCP
      -- master methods
      bind: function(TCP, string, integer)
      connect: function(TCP, string, integer): integer, string
      listen: function(TCP, integer): integer, string

      -- client methods
      getpeername: function(TCP): string, integer

      enum TCPReceivePattern
         "*l"
         "*a"
      end
      enum TCPReceiveError
         "closed"
         "timeout"
      end
      receive: function(TCP, TCPReceivePattern|integer, string): string, TCPReceiveError

      send: function(TCP, string, integer, integer): integer, string, integer

      enum TCPShutdownMode
         "both"
         "send"
         "receive"
      end
      shutdown: function(TCP, TCPShutdownMode): integer

      -- server methods
      accept: function(TCP): TCP, string

      -- client and server methods
      enum TCPOption
         "keepalive"
         "reuseaddr"
         "tcp-nodelay"
      end
      enum TCPLinger
         "linger"
      end
      record TCPLingerOption
         on: boolean
         timeout: integer
      end
      setoption: function(TCP, TCPOption): integer
      setoption: function(TCP, TCPLinger, TCPLingerOption): integer

      -- master, client, and server methods
      close: function(TCP)

      getsockname: function(TCP): string, integer

      getstats: function(TCP): integer, integer, integer

      setstats: function(TCP, integer, integer, integer): integer

      enum TCPTimeoutMode
         "b"
         "t"
      end
      settimeout: function(TCP, integer, TCPTimeoutMode)
   end
   record UDP
      close: function(UDP)

      getpeername: function(UDP): string, integer

      getsockname: function(UDP): string, integer

      enum UDPTimeout
         "timeout"
      end
      receive: function(UDP, integer): string, UDPTimeout

      receivefrom: function(UDP, integer): string, string, integer, UDPTimeout

      send: function(UDP, string): integer, string

      sendto: function(UDP, string, string, integer): integer, string

      setpeername: function(UDP, string, integer): integer, string

      setsockname: function(UDP, string, integer): integer, string

      enum UDPOptions
         "dontroute"
         "broadcast"
      end
      setoption: function(UDP, UDPOptions, boolean): integer, string

      settimeout: function(UDP, integer)
   end
   tcp: function(): TCP, string

   udp: function(): UDP, string

   record dns
      record DNSResolved
         name: string
         alias: {string}
         ip: {string}
      end
      toip: function(): string
      tohostname: function(string): string, DNSResolved|string
      gethostname: function(string): string, DNSResolved|string
   end

   bind: function(string, integer, integer): TCP

   connect: function(string, integer, string, integer): TCP

   _DEBUG: boolean

   newtry: function(function): function

   protect: function(function): function

   -- tagged records/Table Union types would be nice here,
   -- as this should be {TCP|UDP}
   -- but I imagine this should be fine for most uses
   select: function({UDP}, {UDP}, integer): {UDP}, {UDP}, string
   select: function({TCP}, {TCP}, integer): {TCP}, {TCP}, string

   enum SinkMode
      "http-chunked"
      "close-when-done"
      "keep-open"
   end

   sink: function(SinkMode, UDP): Sink
   sink: function(SinkMode, TCP): Sink

   skip: function(integer, ...: any): any...

   sleep: function(integer)

   enum SourceMode
      "http-chunked"
      "by-length"
      "until-closed"
   end

   source: function(SourceMode, TCP, integer): Source
   source: function(SourceMode, UDP, integer): Source

   gettime: function(): integer

   try: function(...: any): any...

   _VERSION: string
end

return socket