-
flags
-
Flags informing ei
about the behaviour of the callbacks. Flags should be bitwise or:ed together. If no flag, is set, the flags
field should contain 0
. Currently, supported flags:
-
EI_SCLBK_FLG_FULL_IMPL
-
If set, the accept()
, connect()
, writev()
, write()
, and read()
callbacks implements timeouts. The timeout is passed in the tmo
argument and is given in milli seconds. Note that the tmo
argument to these callbacks differ from the timeout arguments in the ei
API. Zero means a zero timeout. That is, poll and timeout immediately unless the operation is successful. EI_SCLBK_INF_TMO
(max unsigned
) means infinite timeout. The file descriptor is in blocking mode when a callback is called, and it must be in blocking mode when the callback returns.
If not set, ei
will implement the timeout using select()
in order to determine when to call the callbacks and when to time out. The tmo
arguments of the accept()
, connect()
, writev()
, write()
, and read()
callbacks should be ignored. The callbacks may be called in non-blocking mode. The callbacks are not allowed to change between blocking and non-blocking mode. In order for this to work, select()
needs to interact with the socket primitives used the same way as it interacts with the ordinary socket primitives. If this is not the case, the callbacks need to implement timeouts and this flag should be set.
More flags may be introduced in the future.
-
int (*socket)(void **ctx, void *setup_ctx)
-
Create a socket and a context for the socket.
On success it should set *ctx
to point to a context for the created socket. This context will be passed to all other socket callbacks. This function will be passed the same setup_context
as passed to the preceding ei_connect_init_ussi()
or ei_connect_xinit_ussi()
call.
Note
During the lifetime of a socket, the pointer *ctx
has to remain the same. That is, it cannot later be relocated.
This callback is mandatory.
-
int (*close)(void *ctx)
-
Close the socket identified by ctx
and destroy the context.
This callback is mandatory.
-
int (*listen)(void *ctx, void *addr, int *len, int backlog)
-
Bind the socket identified by ctx
to a local interface and then listen on it.
The addr
and len
arguments are both input and output arguments. When called addr
points to an address structure of length *len
containing information on how to bind the socket. Upon return this callback should have updated the structure referred by addr
with information on how the socket actually was bound. *len
should be updated to reflect the size of *addr
updated. backlog
identifies the size of the backlog for the listen socket.
This callback is mandatory.
-
int (*accept)(void **ctx, void *addr, int *len, unsigned tmo)
-
Accept connections on the listen socket identified by *ctx
.
When a connection is accepted, a new context for the accepted connection should be created and *ctx
should be updated to point to the new context for the accepted connection. When called addr
points to an uninitialized address structure of length *len
. Upon return this callback should have updated this structure with information about the client address. *len
should be updated to reflect the size of *addr
updated.
If the EI_SCLBK_FLG_FULL_IMPL
flag has been set, tmo
contains timeout time in milliseconds.
Note
During the lifetime of a socket, the pointer *ctx
has to remain the same. That is, it cannot later be relocated.
This callback is mandatory.
-
int (*connect)(void *ctx, void *addr, int len, unsigned tmo)
-
Connect the socket identified by ctx
to the address identified by addr
.
When called addr
points to an address structure of length len
containing information on where to connect.
If the EI_SCLBK_FLG_FULL_IMPL
flag has been set, tmo
contains timeout time in milliseconds.
This callback is mandatory.
-
int (*writev)(void *ctx, const void *iov, long iovcnt, ssize_t *len, unsigned tmo)
-
Write data on the connected socket identified by ctx
.
iov
points to an array of struct iovec
structures of length iovcnt
containing data to write to the socket. On success, this callback should set *len
to the amount of bytes successfully written on the socket.
If the EI_SCLBK_FLG_FULL_IMPL
flag has been set, tmo
contains timeout time in milliseconds.
This callback is optional. Set the writev
field in the the ei_socket_callbacks
structure to NULL
if not implemented.
-
int (*write)(void *ctx, const char *buf, ssize_t *len, unsigned tmo)
-
Write data on the connected socket identified by ctx
.
When called buf
points to a buffer of length *len
containing the data to write on the socket. On success, this callback should set *len
to the amount of bytes successfully written on the socket.
If the EI_SCLBK_FLG_FULL_IMPL
flag has been set, tmo
contains timeout time in milliseconds.
This callback is mandatory.
-
int (*read)(void *ctx, char *buf, ssize_t *len, unsigned tmo)
-
Read data on the connected socket identified by ctx
.
buf
points to a buffer of length *len
where the read data should be placed. On success, this callback should update *len
to the amount of bytes successfully read on the socket.
If the EI_SCLBK_FLG_FULL_IMPL
flag has been set, tmo
contains timeout time in milliseconds.
This callback is mandatory.
-
int (*handshake_packet_header_size)(void *ctx, int *sz)
-
Inform about handshake packet header size to use during the Erlang distribution handshake.
On success, *sz
should be set to the handshake packet header size to use. Valid values are 2
and 4
. Erlang TCP distribution use a handshake packet size of 2
and Erlang TLS distribution use a handshake packet size of 4
.
This callback is mandatory.
-
int (*connect_handshake_complete)(void *ctx)
-
Called when a locally started handshake has completed successfully.
This callback is optional. Set the connect_handshake_complete
field in the ei_socket_callbacks
structure to NULL
if not implemented.
-
int (*accept_handshake_complete)(void *ctx)
-
Called when a remotely started handshake has completed successfully.
This callback is optional. Set the accept_handshake_complete
field in the ei_socket_callbacks
structure to NULL
if not implemented.
-
int (*get_fd)(void *ctx, int *fd)
-
Inform about file descriptor used by the socket which is identified by ctx
.
Note
During the lifetime of a socket, the file descriptor has to remain the same. That is, repeated calls to this callback with the same context should
always report the same file descriptor.
The file descriptor has to be a real file descriptor. That is, no other operation should be able to get the same file descriptor until it has been released by the close()
callback.
This callback is mandatory.