7.2. Network API
7.2.1. Reference implementations
Anjay Lite provides a reference implementation of its network API, designed to work with 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 must implement a custom network compatibility layer that Anjay Lite can use.
To help with this process, Anjay Lite includes tutorial examples featuring minimal and compact implementations:
7.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
Currently Anjay Lite supports only UDP binding. We may add support for other bindings in the future.
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 state of the socket. |
7.2.3. Optional functions
Implementing the following additional functions enables enhanced features:
Function |
Purpose |
---|---|
|
Required to support Queue Mode. If Queue Mode is not needed, implement a stub that returns
|
|
Not used directly by Anjay Lite. Useful for gathering statistics on incoming traffic. |
|
Not used directly by Anjay Lite. Useful for gathering statistics on outgoing traffic. |
|
Not used by Anjay Lite. Can be used to suspend the device until a packet is received. |
Note
For signatures and detailed description of listed functions, see include_public/anj/compat/net/anj_net_api.h