From bf738a03368b8de9c574d9631f131c5a520acf7b Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 26 May 2004 04:58:32 +0000 Subject: [PATCH] Working with in the manual. --- TODO | 36 +++++++------- doc/reference.html | 57 +++++++++++----------- doc/socket.html | 117 ++++++++++++++++++++++++++++++++++++++++++++- src/ftp.lua | 2 +- src/smtp.lua | 6 +-- src/tp.lua | 10 ++-- test/testmesg.lua | 3 +- 7 files changed, 170 insertions(+), 61 deletions(-) diff --git a/TODO b/TODO index ca5b445..2d846fe 100644 --- a/TODO +++ b/TODO @@ -19,38 +19,40 @@ * Separar as classes em arquivos * Retorno de sendto em datagram sockets pode ser refused * select sets are now associative +* colocar pump.all, pump.step +* mudar ltn12.html e usar o exemplo source.cat que está muito melhor. +* break smtp.send into c = smtp.open, c:send() c:close() +* fazer com que a socket.source e socket.sink sejam "selectable". +* change mime.eol to output marker on detection of first candidate, instead + of on the second. that way it works in one pass for strings that end with + one candidate. +* unify backbone of smtp and ftp +* unify filter and send/receive callback. new sink/source/pump idea. +* get rid of aux_optlstring +* get rid of unpack in mime.lua +* create socket.(sink|source).simplify +* break chain into a simpler binary chain and a complex (recursive) one. +* Create a passive mode option for the FTP (good for firewall). +* Modules should return their namespace table in the end of the chunk. -colocar pump.all, pump.step e pump.simplify. -mudar ltn12.html e usar o exemplo source.cat que está muito melhor. - -break smtp.send into c = smtp.open, c:send() c:close() +ajeitar o manual sobre select, mais liberal agora +conjunto associativo falar sobre encodet/wrapt/decodet no manual sobre mime RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. HTTP.lua mudou bastante também. - -fazer com que a socket.source e socket.sink sejam "selectable". - -change mime.eol to output marker on detection of first candidate, instead -of on the second. that way it works in one pass for strings that end with -one candidate. +pump.step usado em todo mundo que recebe source ou sink colocar um userdata com gc metamethod pra chamar sock_close (WSAClose); sources ans sinks are always simple in http and ftp and smtp -unify backbone of smtp and ftp expose encode/decode tables to provide extensibility for mime module use coroutines instead of fancy filters -unify filter and send/receive callback. new sink/source/pump idea. -get rid of aux_optlstring -wrap sink and sources with a function that performs the replacement -get rid of unpack in mime.lua check garbage collection in test*.lua pop3??? -break chain into a simpler binary chain and a complex (recursive) one. add socket.TIMEOUT to be default timeout? @@ -123,9 +125,7 @@ to do with it. Make sure nobody can fuck up with the metatables... -Create a passive mode option for the FTP (good for firewall). -Modules should return their namespace table in the end of the chunk. Adjust dates in all files diff --git a/doc/reference.html b/doc/reference.html index 6372e64..ba519c0 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -55,10 +55,10 @@ - +
-Globals +Global symbols
LUASOCKET_LIBNAME, mime, @@ -68,32 +68,6 @@
-
-LuaSocket namespace (socket) -
-bind, -connect, -debug, -dns, -ftp, -http, -protect, -select, -sink, -source, -sleep, -smtp, -time, -tcp, -try, -udp, -url, -version. -
-
- - -
@@ -175,6 +149,33 @@
+ + +
+The socket namespace (socket) +
+bind, +connect, +debug, +dns, +ftp, +http, +protect, +select, +sink, +source, +sleep, +smtp, +time, +tcp, +try, +udp, +url, +version. +
+
+ +
diff --git a/doc/socket.html b/doc/socket.html index 9372648..bde882b 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -33,7 +33,7 @@ -

The LuaSocket namespace

+

The socket namespace

The socket namespace contains the namespace tables for all @@ -74,7 +74,120 @@ The function an equivalent function that instead of throwing exceptoins, returns nil followed by an error message.

- + + +

+socket.select(recvt, sendt [, timeout]) +

+ +

+Waits for a number of sockets to change status. +

+ +

+Recvt is an array with the sockets to test for characters +available for reading. Sockets in the sendt array are watched to +see if it is OK to immediately write on them. Timeout is the +maximum amount of time (in seconds) to wait for a change in status. A +nil, negative or omitted timeout value allows the +function to block indefinitely. Recvt and sendt can also +be empty tables or nil. Non-socket values in the arrays +will be silently ignored. +

+ +

The function returns a table with the sockets ready for +reading, a table with the sockets ready for writing and an error message. +The error message is "timeout" if a timeout condition was met and +nil otherwise. The returned tables are associative, to +simplify the test if a specific socket has changed status. +

+ +

+Important Note: a known bug in WinSock causes select to fail +on non-blocking TCP sockets. The function may return a socket as +writable even though the socket is not ready for sending. +

+ +

+Important note: calling select with a server socket in the receive +parameter before a call to accept does not guarantee +accept will return immediately. +Use the timeout +method or accept might block forever. +

+ +

+Interesting note: as mentioned in some manuals, calling select with both +sets empty and a non-null timeout is a fairly portable way to sleep with +sub-second precision. +

+ + + + +

+socket.sink(mode, socket) +

+ +

+Creates an +LTN012 +sink from a stream socket object. +

+ +

+Mode defines the behaviour of the sink. The following +options are available: +

+ +

+Socket is the stream socket object used to send the data. +

+ +

+The function returns a sink with the appropriate behavior. +

+ + + +

+socket.source(mode, socket [, length]) +

+ +

+Creates an +LTN012 +source from a stream socket object. +

+ +

+Mode defines the behaviour of the source. The following +options are available: +

+ +

+Socket is the stream socket object used to receive the data. +

+ +

+The function returns a source with the appropriate behavior. +

+ +

socket.try(ret1, ret2 ... retN) diff --git a/src/ftp.lua b/src/ftp.lua index ee1f9aa..306b77f 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -114,7 +114,7 @@ function metat.__index:send(sendt) if err then data:close() end return ret, err end - local sink = socket.sink("close-when-empty", data) + local sink = socket.sink("close-when-done", data) socket.try(ltn12.pump.all(sendt.source, sink, checkstep)) if string.find(code, "1..") then socket.try(self.tp:check("2..")) end return 1 diff --git a/src/smtp.lua b/src/smtp.lua index 6ddeaae..8e672a0 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -51,10 +51,10 @@ function metat.__index:rcpt(to) return socket.try(self.tp:check("2..")) end -function metat.__index:data(src) +function metat.__index:data(src, step) socket.try(self.tp:command("DATA")) socket.try(self.tp:check("3..")) - socket.try(self.tp:source(src)) + socket.try(self.tp:source(src, step)) socket.try(self.tp:send("\r\n.\r\n")) return socket.try(self.tp:check("2..")) end @@ -78,7 +78,7 @@ function metat.__index:send(mailt) else self:rcpt(mailt.rcpt) end - self:data(ltn12.source.chain(mailt.source, stuff())) + self:data(ltn12.source.chain(mailt.source, stuff()), mailt.step) end function open(server, port) diff --git a/src/tp.lua b/src/tp.lua index e9e38a1..4f2a615 100644 --- a/src/tp.lua +++ b/src/tp.lua @@ -87,13 +87,9 @@ function metat.__index:getcontrol() return self.control end -function metat.__index:source(src, instr) - while true do - local chunk, err = src() - if not chunk then return not err, err end - local ret, err = self.control:send(chunk) - if not ret then return nil, err end - end +function metat.__index:source(source, step) + local sink = socket.sink("keep-open", self.control) + return ltn12.pump.all(source, sink, step or ltn12.pump.step) end -- closes the underlying control diff --git a/test/testmesg.lua b/test/testmesg.lua index 796977e..8b33133 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua @@ -49,6 +49,5 @@ print(socket.smtp.send { rcpt = "", from = "", source = socket.smtp.message(mesgt), - server = "mail.iis.com.br", - port = 7 + server = "mail.cs.princeton.edu" })