Hi all,

I tumble on a strange behavior on using luasocket UDP sockets. It is a 
borderline usage, but still I am not sure it is a bug or a feature :).
The thing happen when you want to send/receive UDP datagrams that have a size 
of 0.

To produce the thing:
Into the first LuaVM:
> require 'socket'
> u=socket.udp()
> u:setsockname("*", 1025)
> =u:receivefrom()


Into the second LuaVM:
> require 'socket'
> u=socket.udp()
> =u:sendto("", "127.0.0.1", 1025)

The sendto() returns: nil, "refused"
And then the receivefrom() returns also nil, "refused"

I spied the local network, and I saw indeed 1 UDP datagram with the size equal 
to 0.

So despite the errors returned, the UDP datagrams of size 0 seems to be handled 
correctly by the system (Ubuntu 10.10 btw).

I looked at the source code of luasocket. In usocket.c, line 284:
                int socket_recvfrom(p_socket ps, char *data, size_t count, 
size_t *got,
                        SA *addr, socklen_t *len, p_timeout tm) {
                ...
                long taken = (long) recvfrom(*ps, data, count, 0, addr, len);
                ...
                if (taken == 0) return IO_CLOSED;

So a datagram of size zero is considered as a "close". Is this actually true 
for a UDP socket? As it is not connected the notion of 'close' is kind of blur 
to me.

There are similar thing into socket_recv, socket_send and socket_sendto 
functions.

So is this a bug or a feature ?


Cuero



_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to