summaryrefslogtreecommitdiff
path: root/ecp/src/ecp
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/ecp')
-rw-r--r--ecp/src/ecp/core.c28
-rw-r--r--ecp/src/ecp/ext/rbuf_recv.c2
-rw-r--r--ecp/src/ecp/timer.c4
-rw-r--r--ecp/src/ecp/tm.h4
4 files changed, 24 insertions, 14 deletions
diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c
index 1ba042d..3d4342d 100644
--- a/ecp/src/ecp/core.c
+++ b/ecp/src/ecp/core.c
@@ -202,11 +202,14 @@ static int conn_table_insert(ECPConnection *conn) {
}
}
}
-#else
+
+#else /* ECP_WITH_HTABLE */
+
if (sock->conn_table.size == ECP_MAX_SOCK_CONN) return ECP_ERR_FULL;
sock->conn_table.arr[sock->conn_table.size] = conn;
sock->conn_table.size++;
-#endif
+
+#endif /* ECP_WITH_HTABLE */
return ECP_OK;
}
@@ -231,6 +234,7 @@ static void conn_table_remove(ECPConnection *conn) {
int i;
#ifdef ECP_WITH_HTABLE
+
if (ecp_conn_is_outb(conn)) {
for (i=0; i<ECP_MAX_CONN_KEY; i++) {
if (conn->key[i].valid) {
@@ -247,7 +251,9 @@ static void conn_table_remove(ECPConnection *conn) {
}
}
}
-#else
+
+#else /* ECP_WITH_HTABLE */
+
for (i=0; i<sock->conn_table.size; i++) {
if (conn == sock->conn_table.arr[i]) {
while (i < (sock->conn_table.size-1)) {
@@ -259,7 +265,8 @@ static void conn_table_remove(ECPConnection *conn) {
return;
}
}
-#endif
+
+#endif /* ECP_WITH_HTABLE */
}
static void conn_table_remove_addr(ECPConnection *conn) {
@@ -278,6 +285,7 @@ static ECPConnection *conn_table_search(ECPSocket *sock, unsigned char c_idx, ec
#endif
#ifdef ECP_WITH_HTABLE
+
if (c_public) {
return ecp_ht_search(sock->conn_table.keys, c_public);
} else if (addr) {
@@ -285,7 +293,8 @@ static ECPConnection *conn_table_search(ECPSocket *sock, unsigned char c_idx, ec
} else {
return NULL;
}
-#else
+
+#else /* ECP_WITH_HTABLE */
ECPConnection *conn = NULL;
int i;
@@ -319,14 +328,15 @@ static ECPConnection *conn_table_search(ECPSocket *sock, unsigned char c_idx, ec
}
return NULL;
-#endif
+
+#endif /* ECP_WITH_HTABLE */
}
static void conn_table_expire_inb(ECPSocket *sock, ecp_sts_t to) {
ECPConnection *conn;
ECPConnection *to_remove[ECP_MAX_EXP];
int i, remove_cnt;
- ecp_sts_t access_ts, now = ecp_tm_abstime_ms(0);
+ ecp_sts_t access_ts, now = ecp_tm_get_tick();
#ifdef ECP_WITH_HTABLE
struct hashtable_itr itr;
@@ -407,7 +417,7 @@ static void conn_table_expire_inb(ECPSocket *sock, ecp_sts_t to) {
pthread_mutex_unlock(&conn->mutex);
#endif
- if (now - access_ts > to)) {
+ if (now - access_ts > to) {
to_remove[remove_cnt] = conn;
remove_cnt++;
if (remove_cnt == ECP_MAX_EXP) break;
@@ -2185,7 +2195,7 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr,
conn->nonce_in = nonce_in;
conn->nonce_map = nonce_map;
if (is_inb) {
- conn->access_ts = ecp_tm_abstime_ms(0);
+ conn->access_ts = ecp_tm_get_tick();
if (addr) conn->remote.addr = *addr;
}
diff --git a/ecp/src/ecp/ext/rbuf_recv.c b/ecp/src/ecp/ext/rbuf_recv.c
index 81327d5..de25cb6 100644
--- a/ecp/src/ecp/ext/rbuf_recv.c
+++ b/ecp/src/ecp/ext/rbuf_recv.c
@@ -89,7 +89,7 @@ static void msg_flush(ECPRBConn *conn) {
rv = ecp_pld_get_pts(rbuf->arr.pld[idx].buf, rbuf->arr.pld[idx].size, &msg_pts);
if (!rv && buf->deliver_delay) {
- ecp_sts_t now = ecp_tm_abstime_ms(0);
+ ecp_sts_t now = ecp_tm_get_tick();
msg_pts += buf->deliver_delay;
if (ECP_PTS_LT(now, msg_pts)) {
diff --git a/ecp/src/ecp/timer.c b/ecp/src/ecp/timer.c
index 445c343..fb0f62a 100644
--- a/ecp/src/ecp/timer.c
+++ b/ecp/src/ecp/timer.c
@@ -37,7 +37,7 @@ int ecp_timer_push(ECPTimerItem *ti) {
ECPConnection *conn = ti->conn;
ECPTimer *timer = &conn->sock->timer;
- ti->abstime = ecp_tm_abstime_ms(ti->timeout);
+ ti->abstime = ecp_tm_get_tick() + ti->timeout;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&timer->mutex);
@@ -137,7 +137,7 @@ ecp_sts_t ecp_timer_exe(ECPSocket *sock) {
ECPTimer *timer = &sock->timer;
ECPTimerItem to_exec[ECP_MAX_TIMER];
int to_exec_size = 0;
- ecp_sts_t now = ecp_tm_abstime_ms(0);
+ ecp_sts_t now = ecp_tm_get_tick();
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&timer->mutex);
diff --git a/ecp/src/ecp/tm.h b/ecp/src/ecp/tm.h
index af84b66..033a031 100644
--- a/ecp/src/ecp/tm.h
+++ b/ecp/src/ecp/tm.h
@@ -1,4 +1,4 @@
int ecp_tm_init(ECPContext *ctx);
-ecp_sts_t ecp_tm_abstime_ms(ecp_sts_t msec);
-void ecp_tm_sleep_ms(ecp_sts_t msec);
+ecp_sts_t ecp_tm_get_tick(void);
+void ecp_tm_sleep(ecp_sts_t msec);
void ecp_tm_timer_set(ecp_sts_t next);