lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

> I like very much the setfd method added in 2.0, but...

I knew someone would notice the undocumented things before
anyone noticed the new documented things. :o)

> First problem can be worked around setting the fd to INVALID_SOCKET before
> skt:close( ).
> But for the second problem, I suggest to add a socket_destroy ( in tcp.c )
> on the current OS fd before setting the new one.

Since we are talking about being dirty, if I understood your problem,
here is another undocumented ugly thing you can do:

    skt = socket.tcp()
    skt:close()
    skt:setfd(newfd)

Please understand that this is "hacking" LuaSocket.  Setting to a
bogus file descriptor might crash LuaSocket and there is no way I can
prevent it. All I am saying is that (unofficially) skt:close() doesn't
do anything crazy. It just closes the fd.

You can even create a tcp bject and leave it there just to call

    closeme:setfd(f1)
    closeme:close()
    closeme:setfd(f2)
    closeme:close()
    ...

on every fd you have. (ewwwww)

[]s,
Diego.