diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-02-02 06:40:10 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-02-02 06:40:10 +0100 |
commit | 64b55e7e1236121ea4197d9a37cfec43b196cfe8 (patch) | |
tree | eb16f4a2d3eae3d9485eccbd923812a56b627979 /ecp/platform/posix | |
parent | a4401c99c2a54ba9a964317cbff915d40d16e470 (diff) |
moved ecp, platform -> src
Diffstat (limited to 'ecp/platform/posix')
-rw-r--r-- | ecp/platform/posix/Makefile | 19 | ||||
-rw-r--r-- | ecp/platform/posix/platform.mk | 2 | ||||
-rw-r--r-- | ecp/platform/posix/platform_obj.mk | 2 | ||||
-rw-r--r-- | ecp/platform/posix/time.c | 24 | ||||
-rw-r--r-- | ecp/platform/posix/transport.c | 113 | ||||
-rw-r--r-- | ecp/platform/posix/transport.h | 7 |
6 files changed, 0 insertions, 167 deletions
diff --git a/ecp/platform/posix/Makefile b/ecp/platform/posix/Makefile deleted file mode 100644 index 1a3502a..0000000 --- a/ecp/platform/posix/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../common.mk - -obj_tr = transport.o -obj_tm = time.o - - -%.o: %.c - $(CC) $(CFLAGS) -c $< - -all: libecptr.a libecptm.a - -libecptr.a: $(obj_tr) - $(AR) rcs libecptr.a $(obj_tr) - -libecptm.a: $(obj_tm) - $(AR) rcs libecptm.a $(obj_tm) - -clean: - rm -f *.o *.a diff --git a/ecp/platform/posix/platform.mk b/ecp/platform/posix/platform.mk deleted file mode 100644 index 0370c58..0000000 --- a/ecp/platform/posix/platform.mk +++ /dev/null @@ -1,2 +0,0 @@ -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 -LDFLAGS += -lm -pthread diff --git a/ecp/platform/posix/platform_obj.mk b/ecp/platform/posix/platform_obj.mk deleted file mode 100644 index 6ca3b8d..0000000 --- a/ecp/platform/posix/platform_obj.mk +++ /dev/null @@ -1,2 +0,0 @@ -obj += rbuf.o rbuf_send.o rbuf_recv.o msgq.o -subdirs += htable vconn diff --git a/ecp/platform/posix/time.c b/ecp/platform/posix/time.c deleted file mode 100644 index 111e598..0000000 --- a/ecp/platform/posix/time.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <unistd.h> -#include <sys/time.h> - -#include <core.h> -#include <tm.h> - -int ecp_tm_init(ECPContext *ctx) { - return ECP_OK; -} - -ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) { - struct timeval tv; - ecp_cts_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) { - usleep(msec*1000); -} - -void ecp_tm_timer_set(ecp_cts_t next) {}
\ No newline at end of file diff --git a/ecp/platform/posix/transport.c b/ecp/platform/posix/transport.c deleted file mode 100644 index 2032ce2..0000000 --- a/ecp/platform/posix/transport.c +++ /dev/null @@ -1,113 +0,0 @@ -#include <stdlib.h> -#include <unistd.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <poll.h> - -#include <core.h> -#include <tr.h> - -#define ADDR_S_MAX 32 - -int ecp_tr_init(ECPContext *ctx) { - return ECP_OK; -} - -int ecp_tr_addr_eq(ECPNetAddr *addr1, ECPNetAddr *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 rv; - char addr_c[ADDR_S_MAX]; - char *colon = NULL; - char *endptr = NULL; - uint16_t hport; - - memset(addr_c, 0, sizeof(addr_c)); - strncpy(addr_c, addr_s, ADDR_S_MAX-1); - colon = strchr(addr_c, ':'); - if (colon == NULL) return -1; - *colon = '\0'; - colon++; - if (*colon == '\0') return -1; - rv = inet_pton(AF_INET, addr_c, addr->host); - if (rv != 1) return -1; - hport = strtol(colon, &endptr, 10); - if (*endptr != '\0') return -1; - addr->port = htons(hport); - - return 0; -} - -int ecp_tr_open(ECPSocket *sock, void *addr_s) { - struct sockaddr_in _myaddr; - - memset((char *)&_myaddr, 0, sizeof(_myaddr)); - _myaddr.sin_family = AF_INET; - if (addr_s) { - ECPNetAddr addr; - int rv = ecp_tr_addr_set(&addr, addr_s); - if (rv) return rv; - - memcpy((void *)&_myaddr.sin_addr, addr.host, sizeof(addr.host)); - _myaddr.sin_port = addr.port; - } else { - _myaddr.sin_addr.s_addr = htonl(INADDR_ANY); - _myaddr.sin_port = htons(0); - } - - sock->sock = socket(PF_INET, SOCK_DGRAM, 0); - if (sock->sock < 0) return sock->sock; - - int rv = bind(sock->sock, (struct sockaddr *)&_myaddr, sizeof(_myaddr)); - if (rv < 0) { - close(sock->sock); - return rv; - } - return ECP_OK; -} - -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) { - struct sockaddr_in servaddr; - - memset((void *)&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_port = addr->port; - memcpy((void *)&servaddr.sin_addr, addr->host, sizeof(addr->host)); - 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) { - struct sockaddr_in servaddr; - socklen_t addrlen = sizeof(servaddr); - struct pollfd fds[] = { - {sock->sock, POLLIN, 0} - }; - - int rv = poll(fds, 1, timeout); - memset((void *)&servaddr, 0, sizeof(servaddr)); - if (rv == 1) { - ssize_t recvlen = recvfrom(sock->sock, packet->buffer, packet->size, 0, (struct sockaddr *)&servaddr, &addrlen); - if (recvlen < 0) return recvlen; - if (recvlen < ECP_MIN_PKT) return ECP_ERR_RECV; - - if (addr) { - addr->port = servaddr.sin_port; - memcpy(addr->host, (void *)&servaddr.sin_addr, sizeof(addr->host)); - } - return recvlen; - } - return ECP_ERR_TIMEOUT; -} - -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/platform/posix/transport.h b/ecp/platform/posix/transport.h deleted file mode 100644 index 155bd9c..0000000 --- a/ecp/platform/posix/transport.h +++ /dev/null @@ -1,7 +0,0 @@ -#define ECP_IPv4_ADDR_SIZE 4 - -typedef int ECPNetSock; -typedef struct ECPNetAddr { - unsigned char host[ECP_IPv4_ADDR_SIZE]; - uint16_t port; -} ECPNetAddr; |