summaryrefslogtreecommitdiff
path: root/ecp/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/platform')
-rw-r--r--ecp/src/platform/fe310/time.c10
-rw-r--r--ecp/src/platform/fe310/transport.c16
-rw-r--r--ecp/src/platform/fe310/transport.h7
-rw-r--r--ecp/src/platform/posix/platform.mk2
-rw-r--r--ecp/src/platform/posix/platform_obj.mk2
-rw-r--r--ecp/src/platform/posix/time.c9
-rw-r--r--ecp/src/platform/posix/transport.c17
-rw-r--r--ecp/src/platform/posix/transport.h8
8 files changed, 42 insertions, 29 deletions
diff --git a/ecp/src/platform/fe310/time.c b/ecp/src/platform/fe310/time.c
index 3c74933..1e5eb17 100644
--- a/ecp/src/platform/fe310/time.c
+++ b/ecp/src/platform/fe310/time.c
@@ -1,3 +1,5 @@
+#include <stdlib.h>
+
#include <core.h>
#include <tr.h>
@@ -9,7 +11,7 @@
extern ECPSocket *_ecp_tr_sock;
static void timer_handler(unsigned char type) {
- ecp_cts_t next = ecp_timer_exe(_ecp_tr_sock);
+ ecp_sts_t next = ecp_timer_exe(_ecp_tr_sock);
if (next) {
eos_timer_set(next, EOS_TIMER_ETYPE_ECP);
}
@@ -21,15 +23,15 @@ int ecp_tm_init(ECPContext *ctx) {
return ECP_OK;
}
-ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
+ecp_sts_t ecp_tm_abstime_ms(ecp_sts_t msec) {
return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ + msec;
}
-void ecp_tm_sleep_ms(ecp_cts_t msec) {
+void ecp_tm_sleep_ms(ecp_sts_t msec) {
eos_time_sleep(msec);
}
-void ecp_tm_timer_set(ecp_cts_t next) {
+void ecp_tm_timer_set(ecp_sts_t next) {
uint32_t _next = eos_timer_get(EOS_TIMER_ETYPE_ECP);
if ((_next == EOS_TIMER_NONE) || (next < _next)) eos_timer_set(next, EOS_TIMER_ETYPE_ECP);
}
diff --git a/ecp/src/platform/fe310/transport.c b/ecp/src/platform/fe310/transport.c
index 777a956..b551c51 100644
--- a/ecp/src/platform/fe310/transport.c
+++ b/ecp/src/platform/fe310/transport.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include <core.h>
#include <tr.h>
@@ -11,7 +12,7 @@ static unsigned char _flags = 0;
ECPSocket *_ecp_tr_sock = NULL;
static void packet_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- ECPNetAddr addr;
+ ecp_tr_addr_t addr;
ECP2Buffer bufs;
ECPBuffer packet;
@@ -49,13 +50,18 @@ int ecp_tr_init(ECPContext *ctx) {
return ECP_OK;
}
-int ecp_tr_addr_eq(ECPNetAddr *addr1, ECPNetAddr *addr2) {
+unsigned int ecp_tr_addr_hash(ecp_tr_addr_t *addr) {
+ unsigned int ret = *((unsigned int *)addr->host);
+ return ret ^ ((unsigned int)addr->port << 16);
+}
+
+int ecp_tr_addr_eq(ecp_tr_addr_t *addr1, ecp_tr_addr_t *addr2) {
if (addr1->port != addr2->port) return 0;
if (memcmp(addr1->host, addr2->host, sizeof(addr1->host)) != 0) return 0;
return 1;
}
-int ecp_tr_addr_set(ECPNetAddr *addr, void *addr_s) {
+int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
return ECP_ERR;
}
@@ -74,7 +80,7 @@ void ecp_tr_close(ECPSocket *sock) {
_ecp_tr_sock = NULL;
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
unsigned char *buf = NULL;
int rv;
@@ -94,7 +100,7 @@ ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetA
return msg_size;
}
-ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int timeout) {
+ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
return ECP_ERR;
}
diff --git a/ecp/src/platform/fe310/transport.h b/ecp/src/platform/fe310/transport.h
index 47ad482..213ca11 100644
--- a/ecp/src/platform/fe310/transport.h
+++ b/ecp/src/platform/fe310/transport.h
@@ -1,7 +1,4 @@
#include <eos/sock.h>
-#define ECP_IPv4_ADDR_SIZE 4
-
-typedef EOSNetAddr ECPNetAddr;
-typedef int ECPNetSock;
-
+typedef EOSNetAddr ecp_tr_addr_t;
+typedef int ecp_tr_sock_t;
diff --git a/ecp/src/platform/posix/platform.mk b/ecp/src/platform/posix/platform.mk
index 0370c58..9dcfe37 100644
--- a/ecp/src/platform/posix/platform.mk
+++ b/ecp/src/platform/posix/platform.mk
@@ -1,2 +1,2 @@
-CFLAGS += -O3 -DECP_WITH_PTHREAD=1 -DECP_WITH_HTABLE=1 -DECP_WITH_RBUF=1 -DECP_WITH_MSGQ=1 -DECP_WITH_VCONN=1 -DECP_WITH_DIRSRV -DECP_DEBUG=1
+CFLAGS += -O3 -DECP_WITH_PTHREAD=1 -DECP_WITH_HTABLE=1 -DECP_WITH_VCONN=1 -DECP_WITH_DIR -DECP_WITH_DIRSRV -DECP_WITH_MSGQ=1 -DECP_DEBUG=1
LDFLAGS += -lm -pthread
diff --git a/ecp/src/platform/posix/platform_obj.mk b/ecp/src/platform/posix/platform_obj.mk
index 6ca3b8d..4157ff4 100644
--- a/ecp/src/platform/posix/platform_obj.mk
+++ b/ecp/src/platform/posix/platform_obj.mk
@@ -1,2 +1,2 @@
-obj += rbuf.o rbuf_send.o rbuf_recv.o msgq.o
+obj += ext.o frag.o rbuf.o rbuf_send.o rbuf_recv.o msgq.o
subdirs += htable vconn
diff --git a/ecp/src/platform/posix/time.c b/ecp/src/platform/posix/time.c
index 111e598..efee4f8 100644
--- a/ecp/src/platform/posix/time.c
+++ b/ecp/src/platform/posix/time.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
@@ -8,17 +9,17 @@ int ecp_tm_init(ECPContext *ctx) {
return ECP_OK;
}
-ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
+ecp_sts_t ecp_tm_abstime_ms(ecp_sts_t msec) {
struct timeval tv;
- ecp_cts_t ms_now;
+ ecp_sts_t ms_now;
gettimeofday(&tv, NULL);
ms_now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
return ms_now + msec;
}
-void ecp_tm_sleep_ms(ecp_cts_t msec) {
+void ecp_tm_sleep_ms(ecp_sts_t msec) {
usleep(msec*1000);
}
-void ecp_tm_timer_set(ecp_cts_t next) {} \ No newline at end of file
+void ecp_tm_timer_set(ecp_sts_t next) {}
diff --git a/ecp/src/platform/posix/transport.c b/ecp/src/platform/posix/transport.c
index c41f0df..30822b6 100644
--- a/ecp/src/platform/posix/transport.c
+++ b/ecp/src/platform/posix/transport.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -14,13 +15,18 @@ int ecp_tr_init(ECPContext *ctx) {
return ECP_OK;
}
-int ecp_tr_addr_eq(ECPNetAddr *addr1, ECPNetAddr *addr2) {
+unsigned int ecp_tr_addr_hash(ecp_tr_addr_t *addr) {
+ unsigned int ret = *((unsigned int *)addr->host);
+ return ret ^ ((unsigned int)addr->port << 16);
+}
+
+int ecp_tr_addr_eq(ecp_tr_addr_t *addr1, ecp_tr_addr_t *addr2) {
if (addr1->port != addr2->port) return 0;
if (memcmp(addr1->host, addr2->host, sizeof(addr1->host)) != 0) return 0;
return 1;
}
-int ecp_tr_addr_set(ECPNetAddr *addr, void *addr_s) {
+int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
int rv;
char addr_c[ADDR_S_MAX];
char *colon = NULL;
@@ -49,7 +55,7 @@ int ecp_tr_open(ECPSocket *sock, void *addr_s) {
memset((char *)&_myaddr, 0, sizeof(_myaddr));
_myaddr.sin_family = AF_INET;
if (addr_s) {
- ECPNetAddr addr;
+ ecp_tr_addr_t addr;
int rv = ecp_tr_addr_set(&addr, addr_s);
if (rv) return rv;
@@ -75,7 +81,7 @@ void ecp_tr_close(ECPSocket *sock) {
close(sock->sock);
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
struct sockaddr_in servaddr;
memset((void *)&servaddr, 0, sizeof(servaddr));
@@ -85,7 +91,7 @@ ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetA
return sendto(sock->sock, packet->buffer, msg_size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
}
-ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int timeout) {
+ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
struct sockaddr_in servaddr;
socklen_t addrlen = sizeof(servaddr);
struct pollfd fds[] = {
@@ -111,4 +117,3 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int ti
void ecp_tr_release(ECPBuffer *packet, unsigned char more) {}
void ecp_tr_flag_set(unsigned char flags) {}
void ecp_tr_flag_clear(unsigned char flags) {}
-
diff --git a/ecp/src/platform/posix/transport.h b/ecp/src/platform/posix/transport.h
index 155bd9c..736dbc1 100644
--- a/ecp/src/platform/posix/transport.h
+++ b/ecp/src/platform/posix/transport.h
@@ -1,7 +1,9 @@
#define ECP_IPv4_ADDR_SIZE 4
-typedef int ECPNetSock;
-typedef struct ECPNetAddr {
+struct ECPNetAddr {
unsigned char host[ECP_IPv4_ADDR_SIZE];
uint16_t port;
-} ECPNetAddr;
+};
+
+typedef struct ECPNetAddr ecp_tr_addr_t;
+typedef int ecp_tr_sock_t;