A group of callbacks that define the implementation of sockets; the client must fill this out and pass it to c4socket_registerFactory() before using any socket-based API. More...
#include <c4SocketTypes.h>
kC4NoFraming
if the socket factory acts as a stream of messages, kC4WebSocketClientFraming
or kC4WebSocketServerFraming
if it's a byte stream.
open
callback.
C4Socket
object is being disposed/freed after it's closed.
A group of callbacks that define the implementation of sockets; the client must fill this out and pass it to c4socket_registerFactory() before using any socket-based API.
A group of callbacks that define the implementation of sockets.
These callbacks will be invoked on arbitrary background threads owned by LiteCore. They should return quickly, and perform the operation asynchronously without blocking.
◆ close void(* C4SocketFactory::close) (C4Socket *socket)Called to close the socket.
This is only called if framing
doesn't equal kC4NoFraming
, i.e. the socket operates at the byte level. Otherwise it may be left NULL. No more write calls will be made; you should process any remaining incoming bytes by calling c4socket_received, then call c4socket_closed when the socket closes.
Called to inform the socket that LiteCore has finished processing the data from a c4socket_received call.
This can be used for flow control: you should keep track of the number of bytes you've sent to LiteCore, incrementing the number when you call c4socket_received, and decrementing it when completedReceived
is called. If the number goes above some threshold, you should take measures to stop receiving more data, e.g. by not reading more bytes from the socket. Otherwise memory usage can balloon as more and more data arrives and must be buffered in memory.
data
slice passed to a c4socket_received()
call.)
An arbitrary value that will be passed to the open
callback.
Called to tell the client that a C4Socket
object is being disposed/freed after it's closed.
The implementation of this function can then dispose any state associated with the nativeHandle
.
Set this to NULL if you don't need the call.
This should be set to kC4NoFraming
if the socket factory acts as a stream of messages, kC4WebSocketClientFraming
or kC4WebSocketServerFraming
if it's a byte stream.
Called to open a socket to a destination address.
This function should operate asynchronously, returning immediately. When the socket opens, call c4socket_opened, or if it fails to open, call c4socket_closed with an appropriate error.
nativeHandle
will be NULL; the implementation of this function will probably store a native socket reference there. addr The address (URL) to connect to. options A Fleece-encoded dictionary containing additional parameters, such as kC4SocketOptionWSProtocols
, which provides the WebSocket protocol names to include in the HTTP request header. context The value of the C4SocketFactory
's context
field.
Called to close the socket.
This is only called if framing
equals to kC4NoFraming
, i.e. the socket operates at the message level. Otherwise it may be left NULL.
Your implementation should:
This call can also occur before the socket has opened, if the replicator decides to time out. In this situation – i.e. if you have not yet called c4socket_opened – you should tear down your connection and call c4socket_closed.
C4Socket
to close. status The WebSocket status code to send in the CLOSE message. message The text to send in the CLOSE message.
Called to write to the socket.
If framing
equals kC4NoFraming
, the data is a complete message, and your socket implementation is responsible for framing it; otherwise, it's just raw bytes to write to the stream, including the necessary WebSocket framing.
After data has been written, you must call c4socket_completedWrite. (You can call this once after all the data is written, or multiple times with smaller numbers, as long as the total byte count equals the size of the allocatedData
.)
C4SliceResult
, your implementation of this function is responsible for releasing it when done.
The documentation for this struct was generated from the following file:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4