summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/sock.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-08-09 02:46:08 +0200
committerUros Majstorovic <majstor@majstor.org>2020-08-09 02:46:08 +0200
commit21dbc40e58a79f487d1ee34129f16e26cb6ba120 (patch)
tree8e45719fce0029090792fac08ba42ac2a0371f0e /fw/fe310/eos/sock.c
parent9dd66a7dd0c5ba39f9b602daafea88a00cef75e8 (diff)
message handling iface updated
Diffstat (limited to 'fw/fe310/eos/sock.c')
-rw-r--r--fw/fe310/eos/sock.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/sock.c
index 720e620..9abb9e8 100644
--- a/fw/fe310/eos/sock.c
+++ b/fw/fe310/eos/sock.c
@@ -12,21 +12,21 @@ static eos_evt_handler_t evt_handler[EOS_SOCK_MAX_SOCK];
static void sock_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char sock;
+
if ((buffer == NULL) || (len < 2)) {
eos_net_bad_handler(type, buffer, len);
return;
}
sock = buffer[1];
- if ((sock == 0) || (sock > EOS_SOCK_MAX_SOCK)) {
+ if ((sock == 0) || (sock > EOS_SOCK_MAX_SOCK) || (evt_handler[sock - 1] == NULL)) {
eos_net_bad_handler(type, buffer, len);
return;
}
- sock--;
switch(buffer[0]) {
case EOS_SOCK_MTYPE_PKT:
- evt_handler[sock](type, buffer, len);
+ evt_handler[sock - 1](type, buffer, len);
break;
default:
eos_net_bad_handler(type, buffer, len);
@@ -38,17 +38,16 @@ void eos_sock_init(void) {
int i;
for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
- evt_handler[i] = eos_net_bad_handler;
+ evt_handler[i] = NULL;
}
eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handle_evt);
}
void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler) {
- if (handler == NULL) handler = eos_net_bad_handler;
if (sock && (sock <= EOS_SOCK_MAX_SOCK)) evt_handler[sock - 1] = handler;
}
-int eos_sock_open_udp(void) {
+int eos_sock_open_udp(eos_evt_handler_t handler) {
unsigned char type = EOS_SOCK_MTYPE_OPEN_DGRAM;
unsigned char *buffer = eos_net_alloc();
uint16_t buf_size;
@@ -68,6 +67,8 @@ int eos_sock_open_udp(void) {
eos_net_free(buffer, 1);
if (sock == 0) return EOS_ERR_NET;
+
+ eos_sock_set_handler(sock, handler);
return sock;
}
@@ -76,6 +77,7 @@ void eos_sock_close(unsigned char sock) {
buffer[0] = EOS_SOCK_MTYPE_CLOSE;
buffer[1] = sock;
eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 2, 1);
+ eos_sock_set_handler(sock, NULL);
}
int eos_sock_sendto(unsigned char sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr) {