forked from usedbytes/picowota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp_comm.h
35 lines (27 loc) · 1.05 KB
/
tcp_comm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Copyright (c) 2022 Brian Starkey <stark3y@gmail.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __TCP_COMM_H__
#define __TCP_COMM_H__
#include <stdint.h>
#include <stdbool.h>
#define TCP_COMM_MAX_DATA_LEN 1024
#define TCP_COMM_RSP_OK (('O' << 0) | ('K' << 8) | ('O' << 16) | ('K' << 24))
#define TCP_COMM_RSP_ERR (('E' << 0) | ('R' << 8) | ('R' << 16) | ('!' << 24))
struct comm_command {
uint32_t opcode;
uint32_t nargs;
uint32_t resp_nargs;
uint32_t (*size)(uint32_t *args_in, uint32_t *data_len_out, uint32_t *resp_data_len_out);
uint32_t (*handle)(uint32_t *args_in, uint8_t *data_in, uint32_t *resp_args_out, uint8_t *resp_data_out);
};
struct tcp_comm_ctx;
err_t tcp_comm_listen(struct tcp_comm_ctx *ctx, uint16_t port);
err_t tcp_comm_server_close(struct tcp_comm_ctx *ctx);
bool tcp_comm_server_done(struct tcp_comm_ctx *ctx);
struct tcp_comm_ctx *tcp_comm_new(const struct comm_command *const *cmds,
unsigned int n_cmds, uint32_t sync_opcode);
void tcp_comm_delete(struct tcp_comm_ctx *ctx);
#endif /* __TCP_COMM_H__ */