Line data Source code
1 : #ifndef _SENTINEL_MINIPOT_H_ 2 : #define _SENTINEL_MINIPOT_H_ 3 : 4 : #include <minipot_config.h> 5 : #include <minipot_sentinel_msg_packer.h> 6 : #include <event.h> 7 : 8 : #define MINIPOT_RECV_BUFF_LEN BUFSIZ 9 : 10 : struct minipot { 11 : int report_fd; 12 : struct event_base *ev_base; 13 : struct event *sigint_ev; 14 : minipot_sentinel_msg_packer_t smsg_packer; 15 : uint8_t *recv_buff; 16 : // for each port there is one listening FD and one event 17 : size_t ports_cnt; 18 : int *listen_fds; 19 : struct event **accept_evs; 20 : }; 21 : 22 : // Initializes an instance - allocates its resources. 23 0 : void minipot_init(struct minipot *self, const struct minipot_config *config, 24 : int pipe_write_fd, event_callback_fn accept_cb, void *accept_cb_arg) 25 : __attribute__((nonnull)); 26 : 27 : // Deinitializes an instance - frees its resources. 28 0 : void minipot_destroy(struct minipot *) __attribute__((nonnull)); 29 : 30 : // Starts underlying event loop - starts handling active events. 31 : // Returns 0 if successful, -1 if an error occurred, 32 : // or 1 if no events were pending or active. 33 0 : int minipot_run(struct minipot *) __attribute__((nonnull)); 34 : 35 : // Breaks underlying event loop - stops handling active events. 36 : // Returns 0 if successful otherwise -1. 37 0 : int minipot_stop(struct minipot *) __attribute__((nonnull)); 38 : 39 : // Activates all accept events. Returns 0 if all the events were added 40 : // successfuly otherwise -1. 41 0 : int minipot_start_accept_new_conn(struct minipot *) __attribute__((nonnull)); 42 : 43 : // Deactivates an accept event. Returns 0 if all the events were deleted 44 : // successfuly otherwise -1. 45 0 : int minipot_stop_accept_new_conn(struct minipot *) __attribute__((nonnull)); 46 : 47 : #endif