Add improved datagram support for BSD

This commit is contained in:
Sergio R. Caprile committed 2026-11-20 13:50:25 -03:00
1 parent 0f319e3060
commit 0914048424
9 files changed
+629 -118

No files matched your search

@@ -6,7 +6,6 @@
#include "mongoose.h"
#include <stdio.h>
#include <stdlib.h>
struct echo_server {
@@ -43,12 +42,12 @@ int echo_init(uint16_t port) {
if (fd < 0 || !echo_nonblock(fd) ||
bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0 || listen(fd, 3) < 0) {
printf("BSD echo init: %d\n", errno);
MG_ERROR(("BSD echo init: %d", errno));
if (fd >= 0) close(fd);
return 0;
}
s_server.sock = fd;
printf("BSD echo server on port %hu\n", port);
MG_INFO(("BSD echo server on port %hu", port));
return 1;
}
@@ -80,7 +79,7 @@ void echo_poll(void) {
if (fd >= 0) {
c = (struct echo_client *) calloc(1, sizeof(*c));
if (c == NULL || !echo_nonblock(fd)) {
printf("BSD echo accept: %d\n", c == NULL ? ENOMEM : errno);
MG_ERROR(("BSD echo accept: %d", c == NULL ? ENOMEM : errno));
close(fd);
free(c);
} else {