diff options
Diffstat (limited to 'ecp/src/platform/posix')
-rw-r--r-- | ecp/src/platform/posix/platform.mk | 2 | ||||
-rw-r--r-- | ecp/src/platform/posix/platform_obj.mk | 2 | ||||
-rw-r--r-- | ecp/src/platform/posix/time.c | 9 | ||||
-rw-r--r-- | ecp/src/platform/posix/transport.c | 17 | ||||
-rw-r--r-- | ecp/src/platform/posix/transport.h | 8 |
5 files changed, 23 insertions, 15 deletions
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; |