mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-02 13:20:51 +00:00
Make it legal to have a conn with INVALID_SOCKET
E.g. a timer-only connection PUBLISHED_FROM=e8d4d2b6e5e0dfa8e8f987b2ded6b973c39e2919
This commit is contained in:
1 parent
0456f0f59b
commit
3327e0e871
1 file changed
+30
-27
+30
-27
@@ -3721,27 +3721,28 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
|
|||||||
mg_add_to_set(mgr->ctl[1], &read_set, &max_fd);
|
mg_add_to_set(mgr->ctl[1], &read_set, &max_fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: it is ok to have connections with sock == INVALID_SOCKET in the list,
|
||||||
|
* e.g. timer-only "connections".
|
||||||
|
*/
|
||||||
min_timer = 0;
|
min_timer = 0;
|
||||||
for (nc = mgr->active_connections, num_fds = 0; nc != NULL; nc = tmp) {
|
for (nc = mgr->active_connections, num_fds = 0; nc != NULL; nc = tmp) {
|
||||||
tmp = nc->next;
|
tmp = nc->next;
|
||||||
|
|
||||||
if (nc->sock == INVALID_SOCKET) {
|
if (nc->sock != INVALID_SOCKET) {
|
||||||
mg_mgr_handle_conn(nc, 0, now);
|
num_fds++;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_fds++;
|
if (!(nc->flags & MG_F_WANT_WRITE) &&
|
||||||
|
nc->recv_mbuf.len < nc->recv_mbuf_limit &&
|
||||||
|
(!(nc->flags & MG_F_UDP) || nc->listener == NULL)) {
|
||||||
|
mg_add_to_set(nc->sock, &read_set, &max_fd);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(nc->flags & MG_F_WANT_WRITE) &&
|
if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
|
||||||
nc->recv_mbuf.len < nc->recv_mbuf_limit &&
|
(nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING))) {
|
||||||
(!(nc->flags & MG_F_UDP) || nc->listener == NULL)) {
|
mg_add_to_set(nc->sock, &write_set, &max_fd);
|
||||||
mg_add_to_set(nc->sock, &read_set, &max_fd);
|
mg_add_to_set(nc->sock, &err_set, &max_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
|
|
||||||
(nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING))) {
|
|
||||||
mg_add_to_set(nc->sock, &write_set, &max_fd);
|
|
||||||
mg_add_to_set(nc->sock, &err_set, &max_fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc->ev_timer_time > 0) {
|
if (nc->ev_timer_time > 0) {
|
||||||
@@ -3781,22 +3782,24 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
|
|||||||
|
|
||||||
for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
|
for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
|
||||||
int fd_flags = 0;
|
int fd_flags = 0;
|
||||||
if (num_ev > 0) {
|
if (nc->sock != INVALID_SOCKET) {
|
||||||
fd_flags = (FD_ISSET(nc->sock, &read_set) ? _MG_F_FD_CAN_READ : 0) |
|
if (num_ev > 0) {
|
||||||
(FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
|
fd_flags = (FD_ISSET(nc->sock, &read_set) ? _MG_F_FD_CAN_READ : 0) |
|
||||||
(FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
|
(FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
|
||||||
}
|
(FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
|
||||||
|
}
|
||||||
#ifdef MG_CC3200
|
#ifdef MG_CC3200
|
||||||
// CC3200 does not report UDP sockets as writeable.
|
// CC3200 does not report UDP sockets as writeable.
|
||||||
if (nc->flags & MG_F_UDP &&
|
if (nc->flags & MG_F_UDP &&
|
||||||
(nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
|
(nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
|
||||||
fd_flags |= _MG_F_FD_CAN_WRITE;
|
fd_flags |= _MG_F_FD_CAN_WRITE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef MG_LWIP
|
#ifdef MG_LWIP
|
||||||
/* With LWIP socket emulation layer, we don't get write events */
|
/* With LWIP socket emulation layer, we don't get write events */
|
||||||
fd_flags |= _MG_F_FD_CAN_WRITE;
|
fd_flags |= _MG_F_FD_CAN_WRITE;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
tmp = nc->next;
|
tmp = nc->next;
|
||||||
mg_mgr_handle_conn(nc, fd_flags, now);
|
mg_mgr_handle_conn(nc, fd_flags, now);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user