refactor: started lnm library
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
1587b923c1
commit
20b6b593eb
7 changed files with 237 additions and 0 deletions
25
lnm/include/lnm/common.h
Normal file
25
lnm/include/lnm/common.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef LNM_COMMON
|
||||
#define LNM_COMMON
|
||||
|
||||
#define LNM_RES(x) \
|
||||
{ \
|
||||
lnm_err res = x; \
|
||||
if (res != lnm_err_ok) \
|
||||
return res; \
|
||||
}
|
||||
|
||||
#define LNM_RES2(x, e) \
|
||||
{ \
|
||||
lnm_err res = x; \
|
||||
if (res != lnm_err_ok) { \
|
||||
e; \
|
||||
return res; \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
lnm_err_ok = 0,
|
||||
lnm_err_failed_alloc,
|
||||
} lnm_err;
|
||||
|
||||
#endif
|
||||
42
lnm/include/lnm/loop.h
Normal file
42
lnm/include/lnm/loop.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef LNM_LOOP
|
||||
#define LNM_LOOP
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lnm/common.h"
|
||||
|
||||
#define LNM_LOOP_BUF_SIZE 4096
|
||||
|
||||
typedef enum {
|
||||
lnm_loop_state_req = 0,
|
||||
lnm_loop_state_res,
|
||||
lnm_loop_state_end,
|
||||
} lnm_loop_state;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
lnm_loop_state state;
|
||||
void *ctx;
|
||||
struct {
|
||||
char buf[LNM_LOOP_BUF_SIZE];
|
||||
size_t size;
|
||||
size_t read;
|
||||
} r;
|
||||
struct {
|
||||
char buf[LNM_LOOP_BUF_SIZE];
|
||||
size_t size;
|
||||
size_t written;
|
||||
} w;
|
||||
} lnm_loop_conn;
|
||||
|
||||
typedef struct {
|
||||
struct {
|
||||
lnm_loop_conn **arr;
|
||||
size_t len;
|
||||
} conns;
|
||||
void *gctx;
|
||||
lnm_err (*ctx_init)(void **out, void *gctx);
|
||||
void (*ctx_free)(void *ctx);
|
||||
} lnm_loop;
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue