Create a new asynchronous socket within domain of type using protocol from an existing OS handle. It is your responsibility to ensure that handle - in addition to being a valid socket descriptor - fulfills all requirements to be used by AsyncSocket: POSIX: Must be non-blocking (keyword O_NONBLOCK) Windows: Must be overlapped (keyword WSA_FLAG_OVERLAPPED)
Create a new asynchronous socket within domain of type using protocol.
Convenience constructor for when there is only one protocol supporting both domain and type.
Convenience constructor if avoiding SocketType is preferred. Supports only SOCK_STREAM, SOCK_SEQPACKET, SOCK_DGRAM, SOCK_RAW, and SOCK_RDM.
Convenience constructor for when there is only one protocol supporting both domain and type.
Type of callback triggered when a connection-oriented, active socket completes disconnects. The socket will have been killed before the call.
Type of callback triggered when a connection-oriented socket completes connecting
Type of callback triggered when a socker error occured. The socket will have been killed before the call.
Submits an asynchronous request on this socket to accept an incoming connection. Upon successful acceptance of such a connection onAccept will be called with a new AsyncSocket representing the peer.
Assigns the network address pointed to by addr, with addrlen specifying the size, in bytes, of this address, as the local name of this socket.
Convenience wrapper.
Assigns the network address pointed to by addr, with addrlen specifying the size, n bytes, of this address, as the name of the remote socket. For connection-oriented sockets, also start establishing a connection with that socket and call onConnect once it has.
Convenience wrapper.
Get a socket option (taken from std.socket).
Common case of getting integer and boolean options (taken from std.socket).
Removes the socket from the event loop, shutting it down if necessary, and cleans up the underlying resources. Only after this method has been called may the socket instance be deallocated.
Marks the socket as passive and enables acceptance of incoming connections into instances of AsyncSocket. Only after calling this successfully may accept request be submitted via accept.
Submits an asynchronous request on this socket to receive data. Upon successful reception of at most data.length bytes onReceive will be called with the received bytes as a slice of data.
Submits a special asynchronous request on this socket to receive nothing. Also known as a "zero byte receive" onReceive will be called once there is new data on the socket that can be received immediately. Additionally, onReceive may also be called on connection-oriented sockets where the remote peer has disconnected gracefully with no further data being available for reception.
Submits an asynchronous request on this socket to receive data. Upon successful reception of exactly data.lengt bytes onReceive will be called with data.
Submits an asynchronous request on this socket to receive data from an unknown sender, whose address will also be received. Upon successful reception of at most data.length bytes onReceive will be called with the received bytes as a slice of data and from will have been set to the sender's address. This method may only be called on connectionless sockets, to retrieve the remote address on connection-oriented sockets, refer to remoteAddress.
Submits an asynchronous request on this socket to receive a message. Upon successful reception onReceive will be called with the received data. exact indicates whether successful reception requires the entire buffer provided within message to have been filled. If a socket error occurs, but some data has already been received, then onReceive will be called with that partial data regardless of exact. The message must have been allocated using NetworkMessage.alloc and will be freed with NetworkMessage.free after the completion callback returns, or once an error occurs that prevents said callback from being called.
Submits an asynchronous request on this socket to receive a message. Upon successful reception onReceive will be called with the received data. exact indicates whether successful reception requires the entire buffer provided within message to have been filled. If a socket error occurs, but some data has already been received, then onReceive will be called with that partial data regardless of exact.
Reset internal OS socket handle to INVALID_SOCKET and return its previous value
Creates the underlying OS socket - if necessary - and registers the event handler in the underlying OS event loop.
Submits an asynchronous request on this socket to send data. Upon successful transmission onSend will be called.
Submits an asynchronous request on this socket to send a message. Upon successful transmission onSend will be called. The message must have been allocated using NetworkMessage.alloc and will be freed with NetworkMessage.free after the completion callback returns, or once an error occurs that prevents said callback from being called.
Submits an asynchronous request on this socket to send a message. Upon successful transmission onSend will be called.
Submits an asynchronous request on this socket to send data to a specific recipient. Upon successful transmission onSend will be called.
Set a socket option (taken from std.socket).
Common case for setting integer and boolean options (taken from std.socket).
Provides access to event loop information
Returns whether the socket has not yet been killed.
Whether this socket establishes a (stateful) connection to a remote peer.
Whether this socket transceives datagrams.
The underlying OS socket descriptor
Retrieves and clears the most recent error on this socket
Sets this socket's OnClose callback.
Sets this socket's OnConnect callback.
Sets callback for when a socket error has occurred.
Whether this socket has been put into passive mode.
Whether the socket is automatically resubmitting the current receive request upon its successful completion.
Toggles automatic resubmission of the current receive request upon its successful completion. Enabling this primes the socket so that the next receiveMessage will exhibit the behaviour. Any further calls to receiveMessage while active are forbidden; may only be disabled again in the completion callback provided with the receiveMessage that started it. After disabling, may not be reenabled in the same callback.
Event loop of the thread this socket was created on.
Queue of calls to accept.
Queue of calls to receiveMessage.
Queue of requests initiated by sendMessage.
Proactor-model inspired asynchronous socket implementation. In contrast to POSIX.1-2013 readiness I/O - which essentially describes synchronous socket I/O operations with asynchronous notification of future blocking behaviour for said operations - this provides an API for asynchronous socket I/O operations: The three major socket operations accept, receive, and send modeled by this API will submit a request for asynchronous completion; towards that end, each call to these must be provided with a callback that will be called to notify you of said competion. It is therefore not recommended to keep calling any of these three methods in rapid succession, as they will normally not fail (bugs, memory exhaustion, or the operating system not supporting further pending requests excluded) to notify you that you should try again later. They will, however, notify you via the callbacks you provide once a request has been completed, or once there has been a socket error (refer to OnError). It follows that you should usually have only a small number of requests pending on a socket at the same time (preferably at most only a single receive and a single send - respectively a single accept) and submit the next request only once the previous one (of the same type) notifies you of its completion. For connection-oriented, active sockets, connection completion and disconnect (by the remote peer) are handled by OnConnect and OnClose respectively; disconnecting from the remote peer can be initiated with kill and will not trigger OnClose.