mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-16 05:49:53 +02:00
Almost ready to release.
This commit is contained in:
@ -31,8 +31,8 @@
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
int aux_open(lua_State *L);
|
||||
void aux_newclass(lua_State *L, const char *classname, luaL_reg *func);
|
||||
|
@ -4,8 +4,8 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
#include "io.h"
|
||||
#include "timeout.h"
|
||||
|
@ -5,8 +5,9 @@
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "except.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
int except_open(lua_State *L);
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "inet.h"
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
#include "socket.h"
|
||||
#include "timeout.h"
|
||||
|
||||
|
1
src/io.c
1
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";
|
||||
}
|
||||
}
|
||||
|
5
src/io.h
5
src/io.h
@ -15,7 +15,7 @@
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
#include <lua.h>
|
||||
#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 */
|
||||
|
@ -17,15 +17,17 @@
|
||||
/*=========================================================================*\
|
||||
* Standard include files
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#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"
|
||||
|
@ -8,10 +8,10 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#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"
|
||||
|
@ -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)
|
||||
|
11
src/mime.c
11
src/mime.c
@ -6,10 +6,13 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#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);
|
||||
|
11
src/mime.h
11
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 <lua.h>
|
||||
#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
|
||||
|
@ -4,9 +4,10 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lauxlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "options.h"
|
||||
#include "inet.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
#include "socket.h"
|
||||
|
||||
/* option registry */
|
||||
|
@ -6,8 +6,8 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "timeout.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);
|
||||
|
@ -6,8 +6,8 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
||||
|
@ -6,8 +6,8 @@
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "timeout.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
/* timeout control structure */
|
||||
typedef struct t_tm_ {
|
||||
|
@ -6,8 +6,8 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
|
@ -14,7 +14,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
#include "timeout.h"
|
||||
#include "socket.h"
|
||||
|
@ -6,8 +6,8 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include "lua.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
|
Reference in New Issue
Block a user