From 25de5e761daab8b897a4f09ff8503e6f43c299f9 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 3 May 2017 21:10:08 +0200 Subject: initial commit --- code/timer.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 code/timer.h (limited to 'code/timer.h') diff --git a/code/timer.h b/code/timer.h new file mode 100644 index 0000000..dd9a2a8 --- /dev/null +++ b/code/timer.h @@ -0,0 +1,43 @@ +#define ECP_MAX_TIMER 8 + +#define ECP_ERR_MAX_TIMER -110 + +#include + +#ifdef ECP_WITH_PTHREAD +#include +#endif + +struct ECPConnection; +struct ECPSocket; +struct ECPTimerItem; + +typedef int ecp_timer_retry_t (struct ECPConnection *, struct ECPTimerItem *); + +typedef struct ECPTimerItem { + struct ECPConnection *conn; + unsigned char ptype; + unsigned short cnt; + unsigned int abstime; + unsigned int timeout; + ecp_timer_retry_t *retry; + unsigned char *pld; + size_t pld_size; +} ECPTimerItem; + +typedef struct ECPTimer { + ECPTimerItem item[ECP_MAX_TIMER]; + short head; +#ifdef ECP_WITH_PTHREAD + pthread_mutex_t mutex; +#endif +} ECPTimer; + +int ecp_timer_create(ECPTimer *timer); +void ecp_timer_destroy(ECPTimer *timer); +int ecp_timer_item_init(ECPTimerItem *ti, struct ECPConnection *conn, unsigned char ptype, unsigned short cnt, unsigned int timeout); +int ecp_timer_push(struct ECPConnection *conn, ECPTimerItem *ti); +void ecp_timer_pop(struct ECPConnection *conn, unsigned char ptype); +void ecp_timer_remove(struct ECPConnection *conn); +unsigned int ecp_timer_exe(struct ECPSocket *sock); +int ecp_timer_send(struct ECPConnection *conn, ecp_timer_retry_t *send_f, unsigned char ptype, unsigned short cnt, unsigned int timeout); \ No newline at end of file -- cgit v1.2.3