diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-05-19 15:29:21 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-05-19 15:29:21 +0200 |
commit | 67ff1e142a30bf4e799cc486ce2f6eee93c2e448 (patch) | |
tree | 6ea845f58db6ad9f689c4d7f5d68fabfd1ca11b8 | |
parent | 412a8f99928beff605805807b0f07f6bf8d0a965 (diff) |
fe310 update
-rw-r--r-- | ecp/src/ecp/core.c | 28 | ||||
-rw-r--r-- | ecp/src/ecp/ext/rbuf_recv.c | 2 | ||||
-rw-r--r-- | ecp/src/ecp/timer.c | 4 | ||||
-rw-r--r-- | ecp/src/ecp/tm.h | 4 | ||||
-rw-r--r-- | ecp/src/platform/fe310/time.c | 10 | ||||
-rw-r--r-- | ecp/src/platform/fe310/transport.c | 2 | ||||
-rw-r--r-- | ecp/src/platform/fe310/transport.h | 2 | ||||
-rw-r--r-- | ecp/src/platform/posix/time.c | 8 |
8 files changed, 35 insertions, 25 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); diff --git a/ecp/src/platform/fe310/time.c b/ecp/src/platform/fe310/time.c index 1e5eb17..5e4bc26 100644 --- a/ecp/src/platform/fe310/time.c +++ b/ecp/src/platform/fe310/time.c @@ -4,9 +4,9 @@ #include <tr.h> #include <eos/eos.h> -#include <eos/net.h> #include <eos/event.h> -#include <eos/timer.h> +#include <eos/soc/timer.h> +#include <eos/dev/net.h> extern ECPSocket *_ecp_tr_sock; @@ -23,11 +23,11 @@ int ecp_tm_init(ECPContext *ctx) { return ECP_OK; } -ecp_sts_t ecp_tm_abstime_ms(ecp_sts_t msec) { - return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ + msec; +ecp_sts_t ecp_tm_get_tick(void) { + return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ; } -void ecp_tm_sleep_ms(ecp_sts_t msec) { +void ecp_tm_sleep(ecp_sts_t msec) { eos_time_sleep(msec); } diff --git a/ecp/src/platform/fe310/transport.c b/ecp/src/platform/fe310/transport.c index 2640ecf..c359bd1 100644 --- a/ecp/src/platform/fe310/transport.c +++ b/ecp/src/platform/fe310/transport.c @@ -6,7 +6,7 @@ #include <tr.h> #include <eos/eos.h> -#include <eos/net.h> +#include <eos/dev/net.h> ECPSocket *_ecp_tr_sock = NULL; unsigned char pld_buf[ECP_MAX_PLD]; diff --git a/ecp/src/platform/fe310/transport.h b/ecp/src/platform/fe310/transport.h index 1e0c526..52ece15 100644 --- a/ecp/src/platform/fe310/transport.h +++ b/ecp/src/platform/fe310/transport.h @@ -1,4 +1,4 @@ -#include <eos/sock.h> +#include <eos/net/sock.h> typedef struct EOSNetAddr ecp_tr_addr_t; typedef int ecp_tr_sock_t; diff --git a/ecp/src/platform/posix/time.c b/ecp/src/platform/posix/time.c index efee4f8..7030bf3 100644 --- a/ecp/src/platform/posix/time.c +++ b/ecp/src/platform/posix/time.c @@ -9,17 +9,17 @@ int ecp_tm_init(ECPContext *ctx) { return ECP_OK; } -ecp_sts_t ecp_tm_abstime_ms(ecp_sts_t msec) { +ecp_sts_t ecp_tm_get_tick(void) { struct timeval tv; ecp_sts_t ms_now; gettimeofday(&tv, NULL); ms_now = tv.tv_sec * 1000 + tv.tv_usec / 1000; - return ms_now + msec; + return ms_now; } -void ecp_tm_sleep_ms(ecp_sts_t msec) { - usleep(msec*1000); +void ecp_tm_sleep(ecp_sts_t msec) { + usleep(msec * 1000); } void ecp_tm_timer_set(ecp_sts_t next) {} |