8.2. Network API
8.2.1. Overview
Anjay Lite provides a reference implementation of its network API, designed for systems that support the BSD-style socket API. You can find the full implementation in src/anj/compat/posix/anj_socket.c.
If your target platform does not support BSD-style sockets, you’ll need to implement a custom network compatibility layer for Anjay Lite.
To help with this process, Anjay Lite includes a tutorial that demonstrates a minimal network implementation:
Note
For practical guidance, see the Integrations section, which features example implementations of custom networking layers for various platforms. Explore these sections to find platform-specific tips and ready-to-use code samples that can help accelerate your porting process.
8.2.2. Functions to implement
When building a custom networking layer, you must provide implementations for a set of functions.
This tutorial assumes support for UDP connections, and therefore uses the anj_udp_*
naming convention.
Note
Anjay Lite currently supports only UDP and DTLS binding. Support for additional bindings may be added later.
If POSIX socket API is not available:
Use
ANJ_WITH_SOCKET_POSIX_COMPAT=OFF
when running CMake on Anjay Lite.Implement the following mandatory functions:
Function |
Purpose |
---|---|
|
Create and initialize a network context. |
|
Connect the socket to a server address. |
|
Send data through the socket. |
|
Receive data from the socket. |
|
Shut down socket communication. |
|
Close the socket. |
|
Clean up and free the network context. |
|
Returns the maximum size of a buffer that can be passed to |
|
Return the current socket state. |
|
Used by Anjay Lite when entering Queue Mode. Can return |
Attention
Some API functions are allowed to return ANJ_NET_EINPROGRESS
. Note that using this behaviour
may cause library to stuck in continues calling of the function, instead of proceeding with
fallback procedure.
Note
For function signatures and detailed description of listed functions, see
include_public/anj/compat/net/anj_net_api.h
.