summaryrefslogtreecommitdiff
path: root/ecp/src/platform
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
committerUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
commitf2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (patch)
tree68f67274f3464256d051a4a5376e79a0d578838a /ecp/src/platform
parent55474b81146327e8cfa7702fa9366cc7da6562e7 (diff)
vconn bugfix
Diffstat (limited to 'ecp/src/platform')
-rw-r--r--ecp/src/platform/fe310/platform.mk2
-rw-r--r--ecp/src/platform/fe310/platform_obj.mk1
-rw-r--r--ecp/src/platform/fe310/transport.c69
-rw-r--r--ecp/src/platform/fe310/transport.h2
-rw-r--r--ecp/src/platform/posix/platform.mk2
-rw-r--r--ecp/src/platform/posix/platform_obj.mk1
-rw-r--r--ecp/src/platform/posix/transport.c23
7 files changed, 49 insertions, 51 deletions
diff --git a/ecp/src/platform/fe310/platform.mk b/ecp/src/platform/fe310/platform.mk
index 0230f29..0ab0065 100644
--- a/ecp/src/platform/fe310/platform.mk
+++ b/ecp/src/platform/fe310/platform.mk
@@ -1,3 +1,3 @@
fe310_dir = $(abspath $(src_dir)/../../fw/fe310)
include $(fe310_dir)/platform.mk
-CFLAGS += -I$(fe310_dir) -DECP_WITH_VCONN=1 -DECP_DEBUG=1 -D__FE310__
+CFLAGS += -I$(fe310_dir) -D__FE310__
diff --git a/ecp/src/platform/fe310/platform_obj.mk b/ecp/src/platform/fe310/platform_obj.mk
deleted file mode 100644
index 52e4bb1..0000000
--- a/ecp/src/platform/fe310/platform_obj.mk
+++ /dev/null
@@ -1 +0,0 @@
-subdirs += vconn
diff --git a/ecp/src/platform/fe310/transport.c b/ecp/src/platform/fe310/transport.c
index b551c51..2640ecf 100644
--- a/ecp/src/platform/fe310/transport.c
+++ b/ecp/src/platform/fe310/transport.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <core.h>
#include <tr.h>
@@ -7,43 +8,42 @@
#include <eos/eos.h>
#include <eos/net.h>
-static unsigned char _flags = 0;
-
ECPSocket *_ecp_tr_sock = NULL;
+unsigned char pld_buf[ECP_MAX_PLD];
static void packet_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- ecp_tr_addr_t addr;
-
ECP2Buffer bufs;
ECPBuffer packet;
ECPBuffer payload;
- unsigned char pld_buf[ECP_MAX_PLD];
+ ecp_tr_addr_t addr;
+ ssize_t rv;
bufs.packet = &packet;
bufs.payload = &payload;
packet.buffer = buffer+EOS_SOCK_SIZE_UDP_HDR;
- packet.size = ECP_MAX_PKT;
+ packet.size = EOS_NET_MTU-EOS_SOCK_SIZE_UDP_HDR;
payload.buffer = pld_buf;
payload.size = ECP_MAX_PLD;
- if ((buffer == NULL) || (len < EOS_SOCK_SIZE_UDP_HDR)) {
+ if (len < EOS_SOCK_SIZE_UDP_HDR) {
eos_net_free(buffer, 0);
return;
}
- eos_sock_getfrom(buffer, &addr);
- ssize_t rv = ecp_pkt_handle(_ecp_tr_sock, &addr, NULL, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
+ eos_sock_recvfrom(buffer, len, NULL, 0, &addr);
+
+ rv = ecp_pkt_handle(_ecp_tr_sock, NULL, &addr, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
#ifdef ECP_DEBUG
if (rv < 0) {
- char b[16];
- puts("ERR:");
- puts(itoa(rv, b, 10));
- puts("\n");
+ printf("RCV ERR:%d\n", rv);
}
#endif
- if (bufs.packet->buffer) eos_net_free(buffer, 0);
- eos_net_release();
+ if (bufs.packet->buffer) {
+ eos_net_free(buffer, 0);
+ } else {
+ eos_net_release();
+ }
}
int ecp_tr_init(ECPContext *ctx) {
@@ -66,38 +66,43 @@ int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
}
int ecp_tr_open(ECPSocket *sock, void *addr_s) {
- sock->sock = eos_sock_open_udp(packet_handler);
+ sock->sock = eos_sock_open_udp(packet_handler, NULL);
if (sock->sock < 0) {
sock->sock = 0;
- return ECP_ERR_SEND;
+ return ECP_ERR;
}
_ecp_tr_sock = sock;
+
return ECP_OK;
}
void ecp_tr_close(ECPSocket *sock) {
- eos_sock_close(sock->sock);
+ eos_sock_close(sock->sock, NULL);
_ecp_tr_sock = NULL;
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t pkt_size, ecp_tr_addr_t *addr, unsigned char flags) {
unsigned char *buf = NULL;
+ int reply;
int rv;
- flags |= _flags;
- if (packet && packet->buffer) {
- if (flags & ECP_SEND_FLAG_REPLY) {
+ reply = 0;
+ if (flags & ECP_SEND_FLAG_REPLY) {
+ if (flags & ECP_SEND_FLAG_MORE) return ECP_ERR;
+ if (packet->buffer) {
buf = packet->buffer-EOS_SOCK_SIZE_UDP_HDR;
packet->buffer = NULL;
- } else {
- buf = eos_net_alloc();
- memcpy(buf+EOS_SOCK_SIZE_UDP_HDR, packet->buffer, msg_size);
+ reply = 1;
}
+ } else {
+ buf = eos_net_alloc();
}
if (buf == NULL) return ECP_ERR;
- rv = eos_sock_sendto(sock->sock, buf, msg_size+EOS_SOCK_SIZE_UDP_HDR, flags & ECP_SEND_FLAG_MORE, addr);
+
+ rv = eos_sock_sendto_async(sock->sock, reply ? NULL : packet->buffer, pkt_size, addr, buf, !!(flags & ECP_SEND_FLAG_MORE));
if (rv) return ECP_ERR_SEND;
- return msg_size;
+
+ return pkt_size;
}
ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
@@ -105,18 +110,10 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int
}
void ecp_tr_release(ECPBuffer *packet, unsigned char more) {
- if (packet && packet->buffer) {
+ if (packet->buffer) {
eos_net_free(packet->buffer-EOS_SOCK_SIZE_UDP_HDR, more);
packet->buffer = NULL;
} else if (!more) {
eos_net_release();
}
}
-
-void ecp_tr_flag_set(unsigned char flags) {
- _flags |= flags;
-}
-
-void ecp_tr_flag_clear(unsigned char flags) {
- _flags &= ~flags;
-}
diff --git a/ecp/src/platform/fe310/transport.h b/ecp/src/platform/fe310/transport.h
index 213ca11..1e0c526 100644
--- a/ecp/src/platform/fe310/transport.h
+++ b/ecp/src/platform/fe310/transport.h
@@ -1,4 +1,4 @@
#include <eos/sock.h>
-typedef EOSNetAddr ecp_tr_addr_t;
+typedef struct 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 9dcfe37..8932ac4 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_VCONN=1 -DECP_WITH_DIR -DECP_WITH_DIRSRV -DECP_WITH_MSGQ=1 -DECP_DEBUG=1
+CFLAGS += -O3
LDFLAGS += -lm -pthread
diff --git a/ecp/src/platform/posix/platform_obj.mk b/ecp/src/platform/posix/platform_obj.mk
deleted file mode 100644
index 56a76c3..0000000
--- a/ecp/src/platform/posix/platform_obj.mk
+++ /dev/null
@@ -1 +0,0 @@
-subdirs += htable vconn ext dir
diff --git a/ecp/src/platform/posix/transport.c b/ecp/src/platform/posix/transport.c
index 30822b6..ebfbc7b 100644
--- a/ecp/src/platform/posix/transport.c
+++ b/ecp/src/platform/posix/transport.c
@@ -9,7 +9,7 @@
#include <core.h>
#include <tr.h>
-#define ADDR_S_MAX 32
+#define MAX_ADDR_STR 32
int ecp_tr_init(ECPContext *ctx) {
return ECP_OK;
@@ -28,13 +28,13 @@ int ecp_tr_addr_eq(ecp_tr_addr_t *addr1, ecp_tr_addr_t *addr2) {
int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
int rv;
- char addr_c[ADDR_S_MAX];
+ char addr_c[MAX_ADDR_STR];
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);
+ strncpy(addr_c, addr_s, sizeof(addr_c)-1);
colon = strchr(addr_c, ':');
if (colon == NULL) return -1;
*colon = '\0';
@@ -51,12 +51,14 @@ int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
int ecp_tr_open(ECPSocket *sock, void *addr_s) {
struct sockaddr_in _myaddr;
+ int rv;
memset((char *)&_myaddr, 0, sizeof(_myaddr));
_myaddr.sin_family = AF_INET;
if (addr_s) {
ecp_tr_addr_t addr;
- int rv = ecp_tr_addr_set(&addr, addr_s);
+
+ rv = ecp_tr_addr_set(&addr, addr_s);
if (rv) return rv;
memcpy((void *)&_myaddr.sin_addr, addr.host, sizeof(addr.host));
@@ -69,11 +71,12 @@ int ecp_tr_open(ECPSocket *sock, void *addr_s) {
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));
+ rv = bind(sock->sock, (struct sockaddr *)&_myaddr, sizeof(_myaddr));
if (rv < 0) {
close(sock->sock);
return rv;
}
+
return ECP_OK;
}
@@ -81,14 +84,14 @@ void ecp_tr_close(ECPSocket *sock) {
close(sock->sock);
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t pkt_size, ecp_tr_addr_t *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));
+ return sendto(sock->sock, packet->buffer, pkt_size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
}
ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
@@ -97,8 +100,9 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int
struct pollfd fds[] = {
{sock->sock, POLLIN, 0}
};
+ int rv;
- int rv = poll(fds, 1, timeout);
+ 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);
@@ -111,9 +115,8 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int
}
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) {}