73 lines
2 KiB
C
73 lines
2 KiB
C
#if !defined(_NETIO_H_)
|
|
|
|
#define _NETIO_H_ 1
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <sys/epoll.h>
|
|
#include <sys/socket.h>
|
|
|
|
#include "dataq.h"
|
|
#include "mylock.h"
|
|
|
|
typedef int (*msghandler_t)(struct epoll_event*);
|
|
|
|
#define IO_MON_INPUT (0x01)
|
|
#define IO_MON_OUTPUT (0x02)
|
|
|
|
typedef struct {
|
|
uint16_t sz;
|
|
char* data;
|
|
} io_packet_t;
|
|
|
|
typedef struct {
|
|
mylock_t lock;
|
|
int epoll_fd;
|
|
struct epoll_event ev;
|
|
pthread_t worker;
|
|
} iomgr_t;
|
|
|
|
typedef struct {
|
|
mylock_t lock;
|
|
iomgr_t* iomgr;
|
|
int fd;
|
|
int idx;
|
|
int flags;
|
|
unsigned int busy : 1;
|
|
unsigned int needfree : 1;
|
|
uint32_t refcount;
|
|
dataq_t outq;
|
|
uint64_t seq;
|
|
msghandler_t handler;
|
|
void* owner;
|
|
void* data;
|
|
} endpoint_t;
|
|
|
|
extern int netio_write(int, char*, int);
|
|
extern int netio_read(int, char*, int);
|
|
extern int write_packet(int, io_packet_t*);
|
|
extern int alloc_packet(io_packet_t*);
|
|
extern int read_packet(int, io_packet_t*);
|
|
extern void free_packet(io_packet_t*);
|
|
|
|
extern endpoint_t* endpoint_get(void);
|
|
extern int endpoint_init(endpoint_t*, int, int, int, int);
|
|
extern int endpoint_connect(endpoint_t*, char*, int);
|
|
extern int endpoint_accept(endpoint_t*, endpoint_t*);
|
|
extern int endpoint_set_handler(endpoint_t*, msghandler_t, void*);
|
|
extern int endpoint_enq(endpoint_t*, data_item_t*);
|
|
extern data_item_t* endpoint_deq(endpoint_t*);
|
|
extern endpoint_t* endpoint_ref(endpoint_t*);
|
|
extern void endpoint_deref(endpoint_t*);
|
|
extern uint64_t endpoint_getseq(endpoint_t*);
|
|
extern void endpoint_block_tasks(endpoint_t*);
|
|
extern void endpoint_unblock_tasks(endpoint_t*);
|
|
extern int endpoint_is_task_blocked(endpoint_t*);
|
|
|
|
extern int iomgr_init(iomgr_t*);
|
|
extern int iomgr_monitor(iomgr_t*, endpoint_t*);
|
|
extern int iomgr_unmonitor(iomgr_t*, endpoint_t*);
|
|
extern int iomgr_start(iomgr_t*);
|
|
extern int iomgr_fini(iomgr_t*);
|
|
extern int iomgr_stop(iomgr_t*);
|
|
#endif
|