In this example:
>Client send: MDTM test.txt
>Server response: 213 20120824120909
Because FTP server do not open new channel (2XX response)
and LuaSocket try open new channel we get timeout.
```lua
local ftp = require "socket.ftp"
local ltn12 = require "ltn12"
local url = require("socket.url")
local URL = "ftp://USER:TEST@127.0.0.1";
local CMD = 'MDTM test.txt';
-- get timeout
ftp.get{
url = URL;
command = CMD;
sink = ltn12.sink.table{};
}
-- or we can use ftp.command
ftp.command{
url = URL;
command = URL,
check = function(...)
local status, data = ...
return true
end;
}
```
socket.tcp can accept fd and socket type ('master'(default), 'client')
acceptfd method can be used to write multi-threaded server.
```lua
-- main thread
local fd = srv_sock:acceptfd()
Threads.runfile('echo.lua', fd)
-- echo.lua
local fd = ...
local sock = socket.tcp(fd,'client')
```
or to interact with library such as [ESL](http://wiki.freeswitch.org/wiki/Event_Socket_Library)
```lua
local fd = srv_sock:acceptfd()
Threads.runfile('worker.lua', fd)
-- worker.lua
local sock = ESLconnection((...))
```
If we need just close fd (for example we can not run worker thread) we should call `socket.tcp(fd,'client'):close()`
inet_pton was copying the entire sockaddr_in struct,
rather than just the sin_addr field...
I am a bit unsure about the UDP fix, because it may affect
TCP as well. On UDP sockets, when a sendto fails, the next
receive/receivefrom fails with CONNRESET. I changed
sock_recv/sock_recvfrom in wsocket.c to skip the CONNRESET
from the recv/recvfrom, hoping that if the socket is TCP,
sock_waitfd will get the CONNRESET again. The tests pass,
but this should be tested more thoroughly.
Previous implementation was not making sure the socket
had the same family as the addr returned by getaddrinfo.
So instead of "connection refused", we could get "invalid
argument", which was our fault.