summaryrefslogtreecommitdiff
path: root/code/core/timer.h
blob: 5919a42c52391c5b64a1da3c3bc370089dbbf1f7 (plain)
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
36
37
38
39
40
41
#define ECP_MAX_TIMER       8

#define ECP_ERR_MAX_TIMER   -110

#include <stddef.h>

#ifdef ECP_WITH_PTHREAD
#include <pthread.h>
#endif

struct ECPTimerItem;

typedef ssize_t ecp_timer_retry_t (struct ECPConnection *, struct ECPTimerItem *);

typedef struct ECPTimerItem {
    struct ECPConnection *conn;
    unsigned char mtype;
    short cnt;
    ecp_cts_t abstime;
    ecp_cts_t 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 mtype, short cnt, ecp_cts_t timeout);
int ecp_timer_push(ECPTimerItem *ti);
void ecp_timer_pop(struct ECPConnection *conn, unsigned char mtype);
void ecp_timer_remove(struct ECPConnection *conn);
ecp_cts_t ecp_timer_exe(struct ECPSocket *sock);
ssize_t ecp_timer_send(struct ECPConnection *conn, ecp_timer_retry_t *send_f, unsigned char mtype, short cnt, ecp_cts_t timeout);