mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Fix #1382 - use sendto for UDP send
This commit is contained in:
1 parent
c62c8ea4dd
commit
7c5e67b272
5 files changed
+48
-36
No files matched your search
+13
-6
@@ -101,7 +101,14 @@ static struct mg_connection *alloc_conn(struct mg_mgr *mgr, bool is_client,
|
||||
}
|
||||
|
||||
static long mg_sock_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
long n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
||||
long n;
|
||||
if (c->is_udp) {
|
||||
union usa usa;
|
||||
socklen_t slen = tousa(&c->peer, &usa);
|
||||
n = sendto(FD(c), (char *) buf, len, 0, &usa.sa, slen);
|
||||
} else {
|
||||
n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING);
|
||||
}
|
||||
return n == 0 ? -1 : n < 0 && mg_sock_would_block() ? 0 : n;
|
||||
}
|
||||
|
||||
@@ -367,12 +374,12 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
#if MG_ARCH == MG_ARCH_AZURERTOS
|
||||
// AzureRTOS, in non-block socket mode can mark listening socket readable
|
||||
// even it is not. See comment for 'select' func implementation in nx_bsd.c
|
||||
// That's not an error, just should try later
|
||||
if (MG_SOCK_ERRNO != EAGAIN)
|
||||
// AzureRTOS, in non-block socket mode can mark listening socket readable
|
||||
// even it is not. See comment for 'select' func implementation in nx_bsd.c
|
||||
// That's not an error, just should try later
|
||||
if (MG_SOCK_ERRNO != EAGAIN)
|
||||
#endif
|
||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||
#if (!defined(_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
||||
} else if ((long) fd >= FD_SETSIZE) {
|
||||
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
||||
|
||||
Reference in new issue
Block a user