Commit 78454da3 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

BREAKING: Set MG_F_SEND_AND_CLOSE on UDP conns

Long-lived UDP "connections" i.e. interactions that involve more
than one request and response are rare, most are transactional:
response is sent and the "connection" is closed. Or - should be.
But users (including ourselves) tend to forget about that part,
because UDP is connectionless and one does not think about
processing a UDP request as handling a connection that needs to be
closed. Thus, we begin with SEND_AND_CLOSE flag set, which should
be a reasonable default for most use cases, but it is possible to
turn it off the connection should be kept alive after processing.

PUBLISHED_FROM=1677d8024aa9afa7e18d8a04d829b699f7f2f103
parent e62dc8f3
......@@ -2510,6 +2510,18 @@ void mg_if_recv_udp_cb(struct mg_connection *nc, void *buf, int len,
nc->user_data = lc->user_data;
nc->recv_mbuf_limit = lc->recv_mbuf_limit;
nc->flags = MG_F_UDP;
/*
* Long-lived UDP "connections" i.e. interactions that involve more
* than one request and response are rare, most are transactional:
* response is sent and the "connection" is closed. Or - should be.
* But users (including ourselves) tend to forget about that part,
* because UDP is connectionless and one does not think about
* processing a UDP request as handling a connection that needs to be
* closed. Thus, we begin with SEND_AND_CLOSE flag set, which should
* be a reasonable default for most use cases, but it is possible to
* turn it off the connection should be kept alive after processing.
*/
nc->flags |= MG_F_SEND_AND_CLOSE;
mg_add_conn(lc->mgr, nc);
mg_call(nc, NULL, MG_EV_ACCEPT, &nc->sa);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment