TCP/IP Offload
TCP/IP offload APIs to seamlessly integrate and leverage TCP Offload Engine (TOE)
with the existing network infrastructure. In general, we recommend using LD_PRELOAD
which hooks standard POSIX socket APIs to support non-modified applications (e.g., iPerf, Nginx).
However, if you want to develop more optimizd TCP applications, these API will be the best option.
There are three types of handles for TCP APIs:
IPC
IPC server to orchestrate requests and responses.TCP
Per-device TCP connection management.Socket
Per-session socket buffer management.
Example
Here is an example of using TCP offload APIs.
example_toe_client.cc
#include <libmango.h>
int main() {
// open an IPC server
mango_ipc_h ipc;
mango_ipc_open ("localhost:32847", false, &ipc);
// create TCP connected with IPC server
mango_tcp_h tcp;
mango_tcp_create (ipc, &tcp);
mango_tcp_set_ipc (tcp, ipc);
// create TCP socket;
mango_socket_h sock;
mango_socket_create (tcp, &sock);
mango_socket_open (sock, NULL);
// connect to the remote server
struct sockaddr_in addr = { ... };
mango_socket_connect (sock, (struct sockaddr *) &addr, sizeof (addr));
// send data to the remote server
char buf[128];
while (1) {
mango_socket_send (sock, buf, 128, NULL);
...
}
return 0;
}
Datatypes
mango_tcp_h
typedef void * mango_tcp_h;
A handle of mango tcp.
mango_socket_h
typedef void * mango_socket_h;
A handle of mango socket.
mango_ipc_h
typedef void * mango_ipc_h;
A handle of mango ipc.
mango_ipc_prot_e
typedef enum _mango_ipc_prot mango_ipc_prot_e;
Define available IPC protocol type.
Values
MANGO_IPC_PROT_GRPC | gRPC IPC protocol |
MANGO_IPC_PROT_ICEORYX | Iceoryx IPC protocol |
mango_ipc_msg_e
typedef enum _mango_ipc_msg mango_ipc_msg_e;
Define available IPC message type.
Values
MANGO_IPC_MSG_HEALTH_CHECK | Health check message |
MANGO_IPC_MSG_SET_CONFIG | Set configuration message |
MANGO_IPC_MSG_GET_CONFIG | Get configuration message |
MANGO_IPC_MSG_TCP_LISTEN | TCP listen message |
MANGO_IPC_MSG_TCP_ACCEPT | TCP accept message |
MANGO_IPC_MSG_TCP_CONNECT | TCP connect message |
MANGO_IPC_MSG_TCP_CLOSE | TCP close message |
MANGO_IPC_MSG_TCP_LISTEN_CLOSE | TCP listen close message |
MANGO_IPC_MSG_TCP_ABORT | TCP abort message |
Functions
mango_tcp_create
mango_status_e mango_tcp_create(mango_tcp_h *tcp)
Create an tcp handle.
Parameters
- out
tcp
The output tcp handle.
Returns
0
on success, Otherwise, a negative error value.