summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/net/sock.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-08-09 22:23:08 +0200
committerUros Majstorovic <majstor@majstor.org>2022-08-09 22:23:08 +0200
commit3f913efda03fd840cd526ef72e6f397c7da61bd7 (patch)
tree08f62c93e0e0660fdb7beba32276ff1ceb7a8a3c /fw/fe310/eos/net/sock.c
parent810dde21ee65653c15606917b19566cfbaaf165e (diff)
code layout
Diffstat (limited to 'fw/fe310/eos/net/sock.c')
-rw-r--r--fw/fe310/eos/net/sock.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/fw/fe310/eos/net/sock.c b/fw/fe310/eos/net/sock.c
index 7365c97..1db0cd9 100644
--- a/fw/fe310/eos/net/sock.c
+++ b/fw/fe310/eos/net/sock.c
@@ -4,7 +4,7 @@
#include "eos.h"
#include "event.h"
-#include "net.h"
+#include "dev/net.h"
#include "sock.h"
@@ -34,7 +34,7 @@ static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_sock_netinit(void) {
+void eos_sock_init(void) {
int i;
for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
@@ -69,20 +69,29 @@ int eos_sock_open_udp(eos_evt_handler_t handler, unsigned char *buffer) {
buffer[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
rv = eos_net_xchg(&type, buffer, &len);
- if (rv) return rv;
+ if (rv) goto sock_open_udp_fin;
- if (type != EOS_NET_MTYPE_SOCK) return EOS_ERR_NET;
- if (len < 2) return EOS_ERR_SIZE;
+ if (type != EOS_NET_MTYPE_SOCK) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
+ }
+ if (len < 2) {
+ rv = EOS_ERR_SIZE;
+ goto sock_open_udp_fin;
+ }
sock = buffer[1];
- if (sock == 0) return EOS_ERR_NET;
-
- if (do_release) {
- eos_net_free(buffer, 1);
+ if (sock == 0) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
}
+
+ rv = sock;
eos_sock_set_handler(sock, handler);
- return sock;
+sock_open_udp_fin:
+ if (do_release) eos_net_free(buffer, 1);
+ return rv;
}
void eos_sock_close(unsigned char sock, unsigned char *buffer) {