mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-28 20:58:31 +00:00
Fix #1382 - use sendto for UDP send
This commit is contained in:
1 parent
c62c8ea4dd
commit
7c5e67b272
4 files changed
+20
-8
No files matched your search
+10
-4
@@ -1475,7 +1475,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
path[path_size - 1] = '\0'; // Double-check
|
path[path_size - 1] = '\0'; // Double-check
|
||||||
remove_double_dots(path);
|
remove_double_dots(path);
|
||||||
n = strlen(path);
|
n = strlen(path);
|
||||||
LOG(LL_DEBUG, ("--> %s", path));
|
LOG(LL_VERBOSE_DEBUG, ("%lu %s", c->id, path));
|
||||||
while (n > 0 && path[n - 1] == '/') path[--n] = 0; // Trim trailing slashes
|
while (n > 0 && path[n - 1] == '/') path[--n] = 0; // Trim trailing slashes
|
||||||
flags = fs->stat(path, NULL, NULL); // Does it exist?
|
flags = fs->stat(path, NULL, NULL); // Does it exist?
|
||||||
if (flags == 0) {
|
if (flags == 0) {
|
||||||
@@ -2828,8 +2828,7 @@ void mg_sntp_send(struct mg_connection *c, unsigned long utc) {
|
|||||||
s_sntmp_next = utc + SNTP_INTERVAL_SEC;
|
s_sntmp_next = utc + SNTP_INTERVAL_SEC;
|
||||||
buf[0] = (3 << 6) | (4 << 3) | 3;
|
buf[0] = (3 << 6) | (4 << 3) | 3;
|
||||||
mg_send(c, buf, sizeof(buf));
|
mg_send(c, buf, sizeof(buf));
|
||||||
LOG(LL_DEBUG,
|
LOG(LL_DEBUG, ("%lu ct %lu, next at %lu", c->id, utc, s_sntmp_next));
|
||||||
("%p request sent, ct %lu, next at %lu", c->fd, utc, s_sntmp_next));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2947,7 +2946,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) {
|
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;
|
return n == 0 ? -1 : n < 0 && mg_sock_would_block() ? 0 : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -725,7 +725,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
path[path_size - 1] = '\0'; // Double-check
|
path[path_size - 1] = '\0'; // Double-check
|
||||||
remove_double_dots(path);
|
remove_double_dots(path);
|
||||||
n = strlen(path);
|
n = strlen(path);
|
||||||
LOG(LL_DEBUG, ("--> %s", path));
|
LOG(LL_VERBOSE_DEBUG, ("%lu %s", c->id, path));
|
||||||
while (n > 0 && path[n - 1] == '/') path[--n] = 0; // Trim trailing slashes
|
while (n > 0 && path[n - 1] == '/') path[--n] = 0; // Trim trailing slashes
|
||||||
flags = fs->stat(path, NULL, NULL); // Does it exist?
|
flags = fs->stat(path, NULL, NULL); // Does it exist?
|
||||||
if (flags == 0) {
|
if (flags == 0) {
|
||||||
|
|||||||
+1
-2
@@ -54,8 +54,7 @@ void mg_sntp_send(struct mg_connection *c, unsigned long utc) {
|
|||||||
s_sntmp_next = utc + SNTP_INTERVAL_SEC;
|
s_sntmp_next = utc + SNTP_INTERVAL_SEC;
|
||||||
buf[0] = (3 << 6) | (4 << 3) | 3;
|
buf[0] = (3 << 6) | (4 << 3) | 3;
|
||||||
mg_send(c, buf, sizeof(buf));
|
mg_send(c, buf, sizeof(buf));
|
||||||
LOG(LL_DEBUG,
|
LOG(LL_DEBUG, ("%lu ct %lu, next at %lu", c->id, utc, s_sntmp_next));
|
||||||
("%p request sent, ct %lu, next at %lu", c->fd, utc, s_sntmp_next));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -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) {
|
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;
|
return n == 0 ? -1 : n < 0 && mg_sock_would_block() ? 0 : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user