From 7195ab620bd5029856a5c6c88e54a9a6eceb5e87 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Tue, 22 Jun 2004 04:49:57 +0000 Subject: [PATCH] Few extra changes. --- src/luasocket.h | 4 ---- src/mime.h | 4 ---- src/smtp.lua | 5 ++++- src/socket.lua | 1 - src/tcp.c | 2 +- src/timeout.c | 3 +-- test/testmesg.lua | 8 +++++--- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/luasocket.h b/src/luasocket.h index 35dc3d9..716b7ff 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -25,10 +25,6 @@ /*-------------------------------------------------------------------------*\ * Initializes the library. \*-------------------------------------------------------------------------*/ -#ifndef LUASOCKET_LIBNAME -#define LUASOCKET_LIBNAME "socket" -#endif - LUASOCKET_API int luaopen_socket(lua_State *L); #endif /* LUASOCKET_H */ diff --git a/src/mime.h b/src/mime.h index ad8a573..688d043 100644 --- a/src/mime.h +++ b/src/mime.h @@ -19,10 +19,6 @@ #define MIME_API extern #endif -#ifndef MIME_LIBNAME -#define MIME_LIBNAME "mime" -#endif - MIME_API int luaopen_mime(lua_State *L); #endif /* MIME_H */ diff --git a/src/smtp.lua b/src/smtp.lua index ac74205..c68b750 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -106,7 +106,10 @@ function open(server, port) local tp = socket.try(tp.connect(server or SERVER, port or PORT, TIMEOUT)) local s = setmetatable({tp = tp}, metat) -- make sure tp is closed if we get an exception - s.try = socket.newtry(function() s:close() end) + s.try = socket.newtry(function() + if s.tp:command("QUIT") then s.tp:check("2..") end + s:close() + end) return s end diff --git a/src/socket.lua b/src/socket.lua index b3889d7..ad96ddb 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -30,7 +30,6 @@ function socket.bind(host, port, backlog) sock:setoption("reuseaddr", true) local res, err = sock:bind(host, port) if not res then return nil, err end - backlog = backlog or 32 res, err = sock:listen(backlog) if not res then return nil, err end return sock diff --git a/src/tcp.c b/src/tcp.c index cbfebdb..1f51b22 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -232,7 +232,7 @@ static int meth_close(lua_State *L) static int meth_listen(lua_State *L) { p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); - int backlog = (int) luaL_checknumber(L, 2); + int backlog = (int) luaL_optnumber(L, 2, 32); const char *err = sock_listen(&tcp->sock, backlog); if (err) { lua_pushnil(L); diff --git a/src/timeout.c b/src/timeout.c index e089051..dcc2105 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -136,8 +136,7 @@ int tm_gettime(void) int tm_gettime(void) { struct timeval v; - struct timezone z = {0, 0}; - gettimeofday(&v, &z); + gettimeofday(&v, (struct timezone *) NULL); return v.tv_sec * 1000 + v.tv_usec/1000; } #endif diff --git a/test/testmesg.lua b/test/testmesg.lua index 3555031..e29b3cb 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua @@ -50,9 +50,11 @@ source = smtp.message{ -- finally send it r, e = smtp.send{ - rcpt = "", - from = "", - source = source + rcpt = {"", + "" }, + from = "", + source = source, + server = "mail.cs.princeton.edu" } print(r, e)