From a32c6d91402329adb769c4fe8bbb24f0d4e99051 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 29 Sep 2005 06:11:42 +0000 Subject: Almost ready to release. --- src/auxiliar.h | 4 ++-- src/buffer.c | 4 ++-- src/buffer.h | 2 +- src/except.c | 5 +++-- src/except.h | 2 +- src/inet.c | 4 ++-- src/inet.h | 2 +- src/io.c | 1 - src/io.h | 5 ++--- src/luasocket.c | 10 ++++++---- src/luasocket.h | 4 ++-- src/makefile | 7 ++++--- src/mime.c | 11 +++++++++-- src/mime.h | 11 +++++++++-- src/options.c | 3 ++- src/options.h | 2 +- src/select.c | 4 ++-- src/socket.h | 1 - src/tcp.c | 4 ++-- src/tcp.h | 2 +- src/timeout.c | 4 ++-- src/timeout.h | 2 +- src/udp.c | 4 ++-- src/udp.h | 2 +- src/unix.c | 4 ++-- src/unix.h | 2 +- src/url.lua | 5 +++++ src/usocket.c | 11 ++--------- src/wsocket.c | 16 +++++----------- 29 files changed, 73 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/auxiliar.h b/src/auxiliar.h index 70f4704..ff20b50 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -31,8 +31,8 @@ * RCS ID: $Id$ \*=========================================================================*/ -#include -#include +#include "lua.h" +#include "lauxlib.h" int aux_open(lua_State *L); void aux_newclass(lua_State *L, const char *classname, luaL_reg *func); diff --git a/src/buffer.c b/src/buffer.c index 1188fda..b69a9b8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -4,8 +4,8 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "buffer.h" diff --git a/src/buffer.h b/src/buffer.h index 8e5fb6c..f43e676 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -17,7 +17,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "io.h" #include "timeout.h" diff --git a/src/except.c b/src/except.c index dabaf19..fc4c038 100644 --- a/src/except.c +++ b/src/except.c @@ -5,8 +5,9 @@ * RCS ID: $Id$ \*=========================================================================*/ #include -#include -#include + +#include "lua.h" +#include "lauxlib.h" #include "except.h" diff --git a/src/except.h b/src/except.h index 2c57b27..03e417d 100644 --- a/src/except.h +++ b/src/except.h @@ -28,7 +28,7 @@ * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" int except_open(lua_State *L); diff --git a/src/inet.c b/src/inet.c index d102060..81ecd22 100644 --- a/src/inet.c +++ b/src/inet.c @@ -7,8 +7,8 @@ #include #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "inet.h" diff --git a/src/inet.h b/src/inet.h index 4b3639a..da95e7e 100644 --- a/src/inet.h +++ b/src/inet.h @@ -16,7 +16,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "socket.h" #include "timeout.h" diff --git a/src/io.c b/src/io.c index fe0af76..317cfd4 100644 --- a/src/io.c +++ b/src/io.c @@ -27,7 +27,6 @@ const char *io_strerror(int err) { case IO_DONE: return NULL; case IO_CLOSED: return "closed"; case IO_TIMEOUT: return "timeout"; - case IO_CLIPPED: return "clipped"; default: return "unknown error"; } } diff --git a/src/io.h b/src/io.h index 4f9de57..bcaf416 100644 --- a/src/io.h +++ b/src/io.h @@ -15,7 +15,7 @@ * RCS ID: $Id$ \*=========================================================================*/ #include -#include +#include "lua.h" #include "timeout.h" @@ -24,8 +24,7 @@ enum { IO_DONE = 0, /* operation completed successfully */ IO_TIMEOUT = -1, /* operation timed out */ IO_CLOSED = -2, /* the connection has been closed */ - IO_CLIPPED = -3, /* maxium bytes count reached */ - IO_UNKNOWN = -4 + IO_UNKNOWN = -3 }; /* interface to error message function */ diff --git a/src/luasocket.c b/src/luasocket.c index 94ea05b..434b5b7 100644 --- a/src/luasocket.c +++ b/src/luasocket.c @@ -17,15 +17,17 @@ /*=========================================================================*\ * Standard include files \*=========================================================================*/ -#include -#include +#include "lua.h" +#include "lauxlib.h" + +#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501) #include "compat-5.1.h" -#include "luasocket.h" +#endif /*=========================================================================*\ * LuaSocket includes \*=========================================================================*/ - +#include "luasocket.h" #include "auxiliar.h" #include "except.h" #include "timeout.h" diff --git a/src/luasocket.h b/src/luasocket.h index c7d09d8..0143fa7 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -8,10 +8,10 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" /*-------------------------------------------------------------------------*\ -* Current luasocket version +* Current socket library version \*-------------------------------------------------------------------------*/ #define LUASOCKET_VERSION "LuaSocket 2.0" #define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" diff --git a/src/makefile b/src/makefile index 7ef18bf..9a97dd3 100644 --- a/src/makefile +++ b/src/makefile @@ -11,6 +11,7 @@ include ../config # Modules belonging to socket-core # SOCKET_OBJS:= \ + $(COMPAT)/compat-5.1.o \ luasocket.o \ timeout.o \ buffer.o \ @@ -22,15 +23,15 @@ SOCKET_OBJS:= \ udp.o \ except.o \ select.o \ - $(COMPAT)/compat-5.1.o \ usocket.o #------ # Modules belonging mime-core # MIME_OBJS:=\ - mime.o \ - $(COMPAT)/compat-5.1.o + $(COMPAT)/compat-5.1.o \ + mime.o + #------ # Modules belonging unix (local domain sockets) diff --git a/src/mime.c b/src/mime.c index 4539e2c..4dfcae5 100644 --- a/src/mime.c +++ b/src/mime.c @@ -6,10 +6,13 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" +#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501) #include "compat-5.1.h" +#endif + #include "mime.h" /*=========================================================================*\ @@ -81,6 +84,10 @@ static UC b64unbase[256]; MIME_API int luaopen_mime_core(lua_State *L) { luaL_openlib(L, "mime", func, 0); + /* make version string available to scripts */ + lua_pushstring(L, "_VERSION"); + lua_pushstring(L, MIME_VERSION); + lua_rawset(L, -3); /* initialize lookup tables */ qpsetup(qpclass, qpunbase); b64setup(b64unbase); diff --git a/src/mime.h b/src/mime.h index eda0898..a56751c 100644 --- a/src/mime.h +++ b/src/mime.h @@ -1,7 +1,7 @@ #ifndef MIME_H #define MIME_H /*=========================================================================*\ -* MIME support functions +* Core MIME support * LuaSocket toolkit * * This module provides functions to implement transfer content encodings @@ -10,7 +10,14 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" + +/*-------------------------------------------------------------------------*\ +* Current MIME library version +\*-------------------------------------------------------------------------*/ +#define MIME_VERSION "MIME 1.0" +#define MIME_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" +#define MIME_AUTHORS "Diego Nehab" /*-------------------------------------------------------------------------*\ * This macro prefixes all exported API functions diff --git a/src/options.c b/src/options.c index c9e69f0..5236a3f 100644 --- a/src/options.c +++ b/src/options.c @@ -4,9 +4,10 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include #include +#include "lauxlib.h" + #include "auxiliar.h" #include "options.h" #include "inet.h" diff --git a/src/options.h b/src/options.h index d57bfaa..6ebf1f6 100644 --- a/src/options.h +++ b/src/options.h @@ -10,7 +10,7 @@ * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "socket.h" /* option registry */ diff --git a/src/select.c b/src/select.c index e2cd91d..d28ade1 100644 --- a/src/select.c +++ b/src/select.c @@ -6,8 +6,8 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "socket.h" #include "timeout.h" diff --git a/src/socket.h b/src/socket.h index 4443bcc..ad12b1b 100644 --- a/src/socket.h +++ b/src/socket.h @@ -53,7 +53,6 @@ int sock_waitfd(p_sock ps, int sw, p_tm tm); int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm); int sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm); -int sock_connected(p_sock ps, p_tm tm); int sock_create(p_sock ps, int domain, int type, int protocol); int sock_bind(p_sock ps, SA *addr, socklen_t addr_len); int sock_listen(p_sock ps, int backlog); diff --git a/src/tcp.c b/src/tcp.c index c79ddd1..8b4c7e3 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -6,8 +6,8 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "auxiliar.h" #include "socket.h" diff --git a/src/tcp.h b/src/tcp.h index 708023e..fe4fd8c 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -16,7 +16,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "buffer.h" #include "timeout.h" diff --git a/src/timeout.c b/src/timeout.c index be68228..4f1d345 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -6,8 +6,8 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "auxiliar.h" #include "timeout.h" diff --git a/src/timeout.h b/src/timeout.h index d2f9be0..27e0a8a 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -6,7 +6,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" /* timeout control structure */ typedef struct t_tm_ { diff --git a/src/udp.c b/src/udp.c index 094e137..4de7248 100644 --- a/src/udp.c +++ b/src/udp.c @@ -6,8 +6,8 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "auxiliar.h" #include "socket.h" diff --git a/src/udp.h b/src/udp.h index 520573d..3591998 100644 --- a/src/udp.h +++ b/src/udp.h @@ -14,7 +14,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "timeout.h" #include "socket.h" diff --git a/src/unix.c b/src/unix.c index c169268..217a600 100644 --- a/src/unix.c +++ b/src/unix.c @@ -6,8 +6,8 @@ \*=========================================================================*/ #include -#include -#include +#include "lua.h" +#include "lauxlib.h" #include "auxiliar.h" #include "socket.h" diff --git a/src/unix.h b/src/unix.h index aaaef3d..60b00fe 100644 --- a/src/unix.h +++ b/src/unix.h @@ -9,7 +9,7 @@ * * RCS ID: $Id$ \*=========================================================================*/ -#include +#include "lua.h" #include "buffer.h" #include "timeout.h" diff --git a/src/url.lua b/src/url.lua index bd39d98..5427cbc 100644 --- a/src/url.lua +++ b/src/url.lua @@ -14,6 +14,11 @@ local table = require("table") module("socket.url") getmetatable(_M).__index = nil +----------------------------------------------------------------------------- +-- Module version +----------------------------------------------------------------------------- +_VERSION = "URL 1.0" + ----------------------------------------------------------------------------- -- Encodes a string into its escaped hexadecimal representation -- Input diff --git a/src/usocket.c b/src/usocket.c index dcb40e6..f067fa1 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -169,15 +169,8 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { /* zero timeout case optimization */ if (tm_iszero(tm)) return IO_TIMEOUT; /* wait until we have the result of the connection attempt or timeout */ - return sock_connected(ps, tm); -} - -/*-------------------------------------------------------------------------*\ -* Checks if socket is connected, or return reason for failure -\*-------------------------------------------------------------------------*/ -int sock_connected(p_sock ps, p_tm tm) { - int err; - if ((err = sock_waitfd(ps, WAITFD_C, tm) == IO_CLOSED)) { + err = sock_waitfd(ps, WAITFD_C, tm); + if (err == IO_CLOSED) { if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE; else return errno; } else return err; diff --git a/src/wsocket.c b/src/wsocket.c index 0f6005f..b533eae 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -22,7 +22,8 @@ int sock_open(void) { WORD wVersionRequested = MAKEWORD(2, 0); int err = WSAStartup(wVersionRequested, &wsaData ); if (err != 0) return 0; - if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) { + if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) && + (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) { WSACleanup(); return 0; } @@ -124,16 +125,8 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { /* zero timeout case optimization */ if (tm_iszero(tm)) return IO_TIMEOUT; /* we wait until something happens */ - return sock_connected(ps, tm); -} - -/*-------------------------------------------------------------------------*\ -* Check if socket is connected -\*-------------------------------------------------------------------------*/ -int sock_connected(p_sock ps, p_tm tm) { - int err; - /* give windows time to find out what is up (yes, disgusting) */ - if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) { + err = sock_waitfd(ps, WAITFD_C, tm); + if (err == IO_CLOSED) { int len = sizeof(err); /* give windows time to set the error (yes, disgusting) */ Sleep(10); @@ -143,6 +136,7 @@ int sock_connected(p_sock ps, p_tm tm) { * "unknown error", but it's not really our fault */ return err > 0? err: IO_UNKNOWN; } else return err; + } /*-------------------------------------------------------------------------*\ -- cgit v1.2.3-55-g6feb