mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-02-13 15:32:52 +01:00
Receive of zero for UDP is now possible.
Previously, receive of zero was considered to be "closed", but that is only true for stream-based protocols, like TCP.
This commit is contained in:
parent
c37f71d062
commit
21698c7665
@ -170,6 +170,9 @@ static int meth_receive(lua_State *L) {
|
|||||||
count = MIN(count, sizeof(buffer));
|
count = MIN(count, sizeof(buffer));
|
||||||
timeout_markstart(tm);
|
timeout_markstart(tm);
|
||||||
err = socket_recv(&udp->sock, buffer, count, &got, tm);
|
err = socket_recv(&udp->sock, buffer, count, &got, tm);
|
||||||
|
/* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */
|
||||||
|
if (err == IO_CLOSED)
|
||||||
|
err = IO_DONE;
|
||||||
if (err != IO_DONE) {
|
if (err != IO_DONE) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, udp_strerror(err));
|
lua_pushstring(L, udp_strerror(err));
|
||||||
@ -194,6 +197,9 @@ static int meth_receivefrom(lua_State *L) {
|
|||||||
count = MIN(count, sizeof(buffer));
|
count = MIN(count, sizeof(buffer));
|
||||||
err = socket_recvfrom(&udp->sock, buffer, count, &got,
|
err = socket_recvfrom(&udp->sock, buffer, count, &got,
|
||||||
(SA *) &addr, &addr_len, tm);
|
(SA *) &addr, &addr_len, tm);
|
||||||
|
/* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */
|
||||||
|
if (err == IO_CLOSED)
|
||||||
|
err = IO_DONE;
|
||||||
if (err == IO_DONE) {
|
if (err == IO_DONE) {
|
||||||
lua_pushlstring(L, buffer, got);
|
lua_pushlstring(L, buffer, got);
|
||||||
lua_pushstring(L, inet_ntoa(addr.sin_addr));
|
lua_pushstring(L, inet_ntoa(addr.sin_addr));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user