@@ -5,18 +5,18 @@ import io.scalajs.nodejs.events.IEventEmitter
5
5
6
6
import scala .scalajs .js
7
7
import scala .scalajs .js .annotation .JSImport
8
+ import scala .scalajs .js .|
8
9
9
10
/**
10
11
* net.Server - This class is used to create a TCP or local server.
11
12
* @see https://nodejs.org/api/net.html#net_class_net_server
12
13
*/
13
14
@ js.native
14
15
@ JSImport (" net" , " Server" )
15
- class Server () extends IEventEmitter {
16
+ class Server (options : ServerOptions = js.native ) extends IEventEmitter {
16
17
17
- // ///////////////////////////////////////////////////////////////////////////////
18
- // Properties
19
- // ///////////////////////////////////////////////////////////////////////////////
18
+ def this (options : ServerOptions , connectionListener : js.Function ) = this ()
19
+ def this (connectionListener : js.Function ) = this ()
20
20
21
21
/**
22
22
* Returns the current number of concurrent connections on the server.
@@ -37,17 +37,13 @@ class Server() extends IEventEmitter {
37
37
*/
38
38
var maxConnections : js.UndefOr [Int ] = js.native
39
39
40
- // ///////////////////////////////////////////////////////////////////////////////
41
- // Methods
42
- // ///////////////////////////////////////////////////////////////////////////////
43
-
44
40
/**
45
41
* Returns the bound address, the address family name and port of the server as reported by the operating system.
46
42
* Useful to find which port was assigned when giving getting an OS-assigned address. Returns an object with
47
43
* three properties, e.g. { port: 12346, family: 'IPv4', address: '127.0.0.1' }
48
44
* @example server.address()
49
45
*/
50
- def address (): Address = js.native
46
+ def address (): Address | String = js.native
51
47
52
48
/**
53
49
* Stops the server from accepting new connections and keeps existing connections. This function is asynchronous,
@@ -56,7 +52,7 @@ class Server() extends IEventEmitter {
56
52
* its only argument if the server was not open when it was closed.
57
53
* @example server.close([callback])
58
54
*/
59
- def close (callback : js.Function = js.native): Unit = js.native
55
+ def close (callback : js.Function1 [io.scalajs.nodejs. SystemError , Any ] = js.native): Unit = js.native
60
56
61
57
/**
62
58
* Asynchronously get the number of concurrent connections on the server. Works when sockets were sent to forks.
@@ -72,34 +68,21 @@ class Server() extends IEventEmitter {
72
68
* @example server.listen(options[, callback])
73
69
*/
74
70
def listen (options : ListenerOptions , callback : js.Function ): Unit = js.native
71
+ def listen (options : ListenerOptions ): Unit = js.native
75
72
76
- /**
77
- * The port, host, and backlog properties of options, as well as the optional callback function, behave as
78
- * they do on a call to server.listen(port[, hostname][, backlog][, callback]). Alternatively, the path
79
- * option can be used to specify a UNIX socket.
80
- * @example server.listen(options[, callback])
81
- */
82
- def listen (options : ListenerOptions ): Unit = js.native
73
+ def listen (handle : Handle , backlog : Int , callback : js.Function ): Unit = js.native
74
+ def listen (handle : Handle , callback : js.Function ): Unit = js.native
75
+ def listen (handle : Handle , backlog : Int ): Unit = js.native
76
+ def listen (handle : Handle ): Unit = js.native
83
77
84
- /**
85
- * @example server.listen(port[, hostname][, backlog][, callback])
86
- */
87
78
def listen (port : Int , hostname : String , backlog : Int , callback : js.Function ): Unit = js.native
88
-
89
- /**
90
- * @example server.listen(port[, hostname][, backlog][, callback])
91
- */
92
- def listen (port : Int , hostname : String , backlog : Int ): Unit = js.native
93
-
94
- /**
95
- * @example server.listen(port[, hostname][, backlog][, callback])
96
- */
97
- def listen (port : Int , hostname : String ): Unit = js.native
98
-
99
- /**
100
- * @example server.listen(port[, hostname][, backlog][, callback])
101
- */
102
- def listen (port : Int ): Unit = js.native
79
+ def listen (port : Int , hostname : String , backlog : Int ): Unit = js.native
80
+ def listen (port : Int , hostname : String , callback : js.Function ): Unit = js.native
81
+ def listen (port : Int , hostname : String ): Unit = js.native
82
+ def listen (port : Int , callback : js.Function ): Unit = js.native
83
+ def listen (port : Int ): Unit = js.native
84
+ def listen (callback : js.Function ): Unit = js.native
85
+ def listen (): Unit = js.native
103
86
104
87
/**
105
88
* Opposite of unref, calling ref on a previously unrefd server will not let the program exit if it's
@@ -116,23 +99,6 @@ class Server() extends IEventEmitter {
116
99
* @example server.unref()
117
100
*/
118
101
def unref (): this .type = js.native
119
-
120
- /**
121
- * Sets the timeout value for sockets, and emits a 'timeout' event on the Server object, passing the socket as
122
- * an argument, if a timeout occurs.
123
- *
124
- * If there is a 'timeout' event listener on the Server object, then it will be called with the timed-out socket
125
- * as an argument.
126
- *
127
- * By default, the Server's timeout value is 2 minutes, and sockets are destroyed automatically if they time out.
128
- * However, if you assign a callback to the Server's 'timeout' event, then you are responsible for handling socket
129
- * timeouts.
130
- * @param msecs the timeout in milliseconds
131
- * @param callback the callback
132
- * @return [[Server ]]
133
- */
134
- def setTimeout (msecs : Double , callback : js.Function ): this .type = js.native
135
-
136
102
}
137
103
138
104
/**
@@ -144,7 +110,7 @@ object Server extends {
144
110
* Server Events
145
111
* @param server the given [[Server ]]
146
112
*/
147
- implicit class ServerEvents (val server : Server ) extends AnyVal {
113
+ implicit final class ServerEvents (val server : Server ) extends AnyVal {
148
114
149
115
/**
150
116
* Emitted when the server closes. Note that if connections exist, this event is not emitted until all
@@ -177,10 +143,3 @@ object Server extends {
177
143
}
178
144
179
145
}
180
-
181
- /**
182
- * Server Options
183
- */
184
- class ServerOptions (val allowHalfOpen : js.UndefOr [Boolean ] = js.undefined,
185
- val pauseOnConnect : js.UndefOr [Boolean ] = js.undefined)
186
- extends js.Object
0 commit comments