From b2724ad2d1cc3768a04270ed3f8014ec65ad133b Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 25 May 2003 01:56:46 +0000 Subject: [PATCH] New sock.h has nothing to do with class sock... --- src/socket.h | 61 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/src/socket.h b/src/socket.h index 9972639..f8c5d8f 100644 --- a/src/socket.h +++ b/src/socket.h @@ -1,24 +1,57 @@ /*=========================================================================*\ -* Socket class: inherits from the File Descriptor class and is here just -* for extensibility in the future +* Socket compatibilization module * -* RCS ID: $id$ +* RCS ID: $Id$ \*=========================================================================*/ -#ifndef SOCK_H_ -#define SOCK_H_ +#ifndef SOCK_H +#define SOCK_H #include -#include "lsfd.h" +#include "error.h" -#define SOCK_CLASS "luasocket(sock)" +/*=========================================================================*\ +* Platform specific compatibilization +\*=========================================================================*/ +#ifdef WIN32 +#include "sockwin32.h" +#else +#include "sockunix.h" +#endif -#define SOCK_FIELDS FD_FIELDS +/* we are lazy... */ +typedef struct sockaddr SA; -typedef t_fd t_sock; -typedef t_sock *p_sock; +/*=========================================================================*\ +* Functions bellow implement a comfortable platform independent +* interface to sockets +\*=========================================================================*/ +int sock_open(lua_State *L); -void sock_open(lua_State *L); -void sock_construct(lua_State *L, p_sock sock); -void sock_inherit(lua_State *L, cchar *lsclass); +const char *sock_create(p_sock ps, int domain, int type, int protocol); +void sock_destroy(p_sock ps); +void sock_accept(p_sock ps, p_sock pa, SA *addr, size_t *addr_len, int timeout); +const char *sock_connect(p_sock ps, SA *addr, size_t addr_len); +const char *sock_bind(p_sock ps, SA *addr, size_t addr_len); +void sock_listen(p_sock ps, int backlog); -#endif /* SOCK_H_ */ +int sock_send(p_sock ps, const char *data, size_t count, + size_t *sent, int timeout); +int sock_recv(p_sock ps, char *data, size_t count, + size_t *got, int timeout); +int sock_sendto(p_sock ps, const char *data, size_t count, + size_t *sent, SA *addr, size_t addr_len, int timeout); +int sock_recvfrom(p_sock ps, char *data, size_t count, + size_t *got, SA *addr, size_t *addr_len, int timeout); + +void sock_setnonblocking(p_sock ps); +void sock_setblocking(p_sock ps); +void sock_setreuseaddr(p_sock ps); + +const char *sock_hoststrerror(void); +const char *sock_createstrerror(void); +const char *sock_bindstrerror(void); +const char *sock_connectstrerror(void); + +const char *sock_trysetoptions(lua_State *L, p_sock ps); + +#endif /* SOCK_H */