mirror of
				https://github.com/lunarmodules/luasocket.git
				synced 2025-10-31 10:25:55 +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:
		| @@ -170,6 +170,9 @@ static int meth_receive(lua_State *L) { | ||||
|     count = MIN(count, sizeof(buffer)); | ||||
|     timeout_markstart(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) { | ||||
|         lua_pushnil(L); | ||||
|         lua_pushstring(L, udp_strerror(err)); | ||||
| @@ -194,6 +197,9 @@ static int meth_receivefrom(lua_State *L) { | ||||
|     count = MIN(count, sizeof(buffer)); | ||||
|     err = socket_recvfrom(&udp->sock, buffer, count, &got,  | ||||
|             (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) { | ||||
|         lua_pushlstring(L, buffer, got); | ||||
|         lua_pushstring(L, inet_ntoa(addr.sin_addr)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user