From 228ab591a65118924cb482f6b9a3a8345bd2cce5 Mon Sep 17 00:00:00 2001 From: Jonas Wielicki Date: Wed, 31 Jul 2013 14:26:25 +0200 Subject: [PATCH] Publish several functions used by luasec --- src/buffer.h | 16 ++++++----- src/common.h | 16 +++++++++++ src/io.h | 7 +++-- src/socket.h | 73 +++++++++++++++++++++++++++++---------------------- src/timeout.h | 19 ++++++++------ 5 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 src/common.h diff --git a/src/buffer.h b/src/buffer.h index 1281bb3..982ee3c 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -20,6 +20,8 @@ #include "io.h" #include "timeout.h" +#include "common.h" + /* buffer size in bytes */ #define BUF_SIZE 8192 @@ -34,12 +36,12 @@ typedef struct t_buffer_ { } t_buffer; typedef t_buffer *p_buffer; -int buffer_open(lua_State *L); -void buffer_init(p_buffer buf, p_io io, p_timeout tm); -int buffer_meth_send(lua_State *L, p_buffer buf); -int buffer_meth_receive(lua_State *L, p_buffer buf); -int buffer_meth_getstats(lua_State *L, p_buffer buf); -int buffer_meth_setstats(lua_State *L, p_buffer buf); -int buffer_isempty(p_buffer buf); +LUASOCKET_API int buffer_open(lua_State *L); +LUASOCKET_API void buffer_init(p_buffer buf, p_io io, p_timeout tm); +LUASOCKET_API int buffer_meth_send(lua_State *L, p_buffer buf); +LUASOCKET_API int buffer_meth_receive(lua_State *L, p_buffer buf); +LUASOCKET_API int buffer_meth_getstats(lua_State *L, p_buffer buf); +LUASOCKET_API int buffer_meth_setstats(lua_State *L, p_buffer buf); +LUASOCKET_API int buffer_isempty(p_buffer buf); #endif /* BUF_H */ diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..9bb0666 --- /dev/null +++ b/src/common.h @@ -0,0 +1,16 @@ +#ifndef LUASOCKET_COMMON_H +#define LUASOCKET_COMMON_H + +#ifndef LUASOCKET_API +#define LUASOCKET_API extern +#endif + +#ifndef UNIX_API +#define UNIX_API extern +#endif + +#ifndef MIME_API +#define MIME_API extern +#endif + +#endif diff --git a/src/io.h b/src/io.h index 76a3e58..2205aaa 100644 --- a/src/io.h +++ b/src/io.h @@ -15,6 +15,8 @@ #include #include "lua.h" +#include "common.h" + #include "timeout.h" /* IO error codes */ @@ -58,8 +60,9 @@ typedef struct t_io_ { } t_io; typedef t_io *p_io; -void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); -const char *io_strerror(int err); +LUASOCKET_API void io_init(p_io io, p_send send, p_recv recv, + p_error error, void *ctx); +LUASOCKET_API const char *io_strerror(int err); #endif /* IO_H */ diff --git a/src/socket.h b/src/socket.h index 63573de..45d1a90 100644 --- a/src/socket.h +++ b/src/socket.h @@ -11,6 +11,8 @@ \*=========================================================================*/ #include "io.h" +#include "common.h" + /*=========================================================================*\ * Platform specific compatibilization \*=========================================================================*/ @@ -35,44 +37,53 @@ typedef struct sockaddr SA; * Functions bellow implement a comfortable platform independent * interface to sockets \*=========================================================================*/ -int socket_open(void); -int socket_close(void); -void socket_destroy(p_socket ps); -void socket_shutdown(p_socket ps, int how); -int socket_sendto(p_socket ps, const char *data, size_t count, - size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); -int socket_recvfrom(p_socket ps, char *data, size_t count, - size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); - -void socket_setnonblocking(p_socket ps); -void socket_setblocking(p_socket ps); - -int socket_waitfd(p_socket ps, int sw, p_timeout tm); -int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, +LUASOCKET_API int socket_open(void); +LUASOCKET_API int socket_close(void); +LUASOCKET_API void socket_destroy(p_socket ps); +LUASOCKET_API void socket_shutdown(p_socket ps, int how); +LUASOCKET_API int socket_sendto(p_socket ps, const char *data, + size_t count, size_t *sent, SA *addr, socklen_t addr_len, + p_timeout tm); +LUASOCKET_API int socket_recvfrom(p_socket ps, char *data, + size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); -int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); -int socket_create(p_socket ps, int domain, int type, int protocol); -int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); -int socket_listen(p_socket ps, int backlog); -int socket_accept(p_socket ps, p_socket pa, SA *addr, +LUASOCKET_API void socket_setnonblocking(p_socket ps); +LUASOCKET_API void socket_setblocking(p_socket ps); + +LUASOCKET_API int socket_waitfd(p_socket ps, int sw, p_timeout tm); +LUASOCKET_API int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, + fd_set *efds, p_timeout tm); + +LUASOCKET_API int socket_connect(p_socket ps, SA *addr, + socklen_t addr_len, p_timeout tm); +LUASOCKET_API int socket_create(p_socket ps, int domain, int type, + int protocol); +LUASOCKET_API int socket_bind(p_socket ps, SA *addr, + socklen_t addr_len); +LUASOCKET_API int socket_listen(p_socket ps, int backlog); +LUASOCKET_API int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm); -const char *socket_hoststrerror(int err); -const char *socket_gaistrerror(int err); -const char *socket_strerror(int err); +LUASOCKET_API const char *socket_hoststrerror(int err); +LUASOCKET_API const char *socket_gaistrerror(int err); +LUASOCKET_API const char *socket_strerror(int err); /* these are perfect to use with the io abstraction module and the buffered input module */ -int socket_send(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); -int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -int socket_write(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); -int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -const char *socket_ioerror(p_socket ps, int err); +LUASOCKET_API int socket_send(p_socket ps, const char *data, + size_t count, size_t *sent, p_timeout tm); +LUASOCKET_API int socket_recv(p_socket ps, char *data, size_t count, + size_t *got, p_timeout tm); +LUASOCKET_API int socket_write(p_socket ps, const char *data, + size_t count, size_t *sent, p_timeout tm); +LUASOCKET_API int socket_read(p_socket ps, char *data, size_t count, + size_t *got, p_timeout tm); +LUASOCKET_API const char *socket_ioerror(p_socket ps, int err); -int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); -int socket_gethostbyname(const char *addr, struct hostent **hp); +LUASOCKET_API int socket_gethostbyaddr(const char *addr, socklen_t len, + struct hostent **hp); +LUASOCKET_API int socket_gethostbyname(const char *addr, + struct hostent **hp); #endif /* SOCKET_H */ diff --git a/src/timeout.h b/src/timeout.h index 6715ca7..dac2a8f 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -6,6 +6,8 @@ \*=========================================================================*/ #include "lua.h" +#include "common.h" + /* timeout control structure */ typedef struct t_timeout_ { double block; /* maximum time for blocking calls */ @@ -14,14 +16,15 @@ typedef struct t_timeout_ { } t_timeout; typedef t_timeout *p_timeout; -int timeout_open(lua_State *L); -void timeout_init(p_timeout tm, double block, double total); -double timeout_get(p_timeout tm); -double timeout_getretry(p_timeout tm); -p_timeout timeout_markstart(p_timeout tm); -double timeout_getstart(p_timeout tm); -double timeout_gettime(void); -int timeout_meth_settimeout(lua_State *L, p_timeout tm); +LUASOCKET_API int timeout_open(lua_State *L); +LUASOCKET_API void timeout_init(p_timeout tm, double block, + double total); +LUASOCKET_API double timeout_get(p_timeout tm); +LUASOCKET_API double timeout_getretry(p_timeout tm); +LUASOCKET_API p_timeout timeout_markstart(p_timeout tm); +LUASOCKET_API double timeout_getstart(p_timeout tm); +LUASOCKET_API double timeout_gettime(void); +LUASOCKET_API int timeout_meth_settimeout(lua_State *L, p_timeout tm); #define timeout_iszero(tm) ((tm)->block == 0.0)