2005-10-07 06:40:59 +02:00
|
|
|
#ifndef SOCKET_H
|
|
|
|
#define SOCKET_H
|
2003-03-28 22:08:50 +01:00
|
|
|
/*=========================================================================*\
|
2003-05-25 03:56:46 +02:00
|
|
|
* Socket compatibilization module
|
2003-06-26 20:47:49 +02:00
|
|
|
* LuaSocket toolkit
|
|
|
|
*
|
|
|
|
* BSD Sockets and WinSock are similar, but there are a few irritating
|
|
|
|
* differences. Also, not all *nix platforms behave the same. This module
|
|
|
|
* (and the associated usocket.h and wsocket.h) factor these differences and
|
|
|
|
* creates a interface compatible with the io.h module.
|
2003-03-28 22:08:50 +01:00
|
|
|
\*=========================================================================*/
|
2003-06-09 20:23:40 +02:00
|
|
|
#include "io.h"
|
2002-07-03 21:06:54 +02:00
|
|
|
|
2003-05-25 03:56:46 +02:00
|
|
|
/*=========================================================================*\
|
|
|
|
* Platform specific compatibilization
|
|
|
|
\*=========================================================================*/
|
2004-06-17 02:18:48 +02:00
|
|
|
#ifdef _WIN32
|
2003-06-09 20:23:40 +02:00
|
|
|
#include "wsocket.h"
|
2003-05-25 03:56:46 +02:00
|
|
|
#else
|
2003-06-09 20:23:40 +02:00
|
|
|
#include "usocket.h"
|
2003-05-25 03:56:46 +02:00
|
|
|
#endif
|
|
|
|
|
2004-01-21 19:40:52 +01:00
|
|
|
/*=========================================================================*\
|
|
|
|
* The connect and accept functions accept a timeout and their
|
|
|
|
* implementations are somewhat complicated. We chose to move
|
|
|
|
* the timeout control into this module for these functions in
|
|
|
|
* order to simplify the modules that use them.
|
|
|
|
\*=========================================================================*/
|
|
|
|
#include "timeout.h"
|
|
|
|
|
2003-05-25 03:56:46 +02:00
|
|
|
/* we are lazy... */
|
|
|
|
typedef struct sockaddr SA;
|
|
|
|
|
|
|
|
/*=========================================================================*\
|
|
|
|
* Functions bellow implement a comfortable platform independent
|
|
|
|
* interface to sockets
|
|
|
|
\*=========================================================================*/
|
2005-10-07 06:40:59 +02:00
|
|
|
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);
|
2005-02-08 11:01:01 +01:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
void socket_setnonblocking(p_socket ps);
|
|
|
|
void socket_setblocking(p_socket ps);
|
2005-02-08 11:01:01 +01:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
int socket_waitfd(p_socket ps, int sw, p_timeout tm);
|
2005-11-20 08:20:26 +01:00
|
|
|
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
|
|
|
|
p_timeout tm);
|
2004-01-24 01:18:19 +01:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
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,
|
|
|
|
socklen_t *addr_len, p_timeout tm);
|
2004-07-15 08:11:53 +02:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
const char *socket_hoststrerror(int err);
|
2012-04-11 22:21:25 +02:00
|
|
|
const char *socket_gaistrerror(int err);
|
2005-10-07 06:40:59 +02:00
|
|
|
const char *socket_strerror(int err);
|
2004-07-15 08:11:53 +02:00
|
|
|
|
|
|
|
/* these are perfect to use with the io abstraction module
|
|
|
|
and the buffered input module */
|
2005-10-07 06:40:59 +02:00
|
|
|
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);
|
2012-02-24 02:12:37 +01:00
|
|
|
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);
|
2005-10-07 06:40:59 +02:00
|
|
|
const char *socket_ioerror(p_socket ps, int err);
|
2004-01-24 01:18:19 +01:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
|
|
|
|
int socket_gethostbyname(const char *addr, struct hostent **hp);
|
2002-07-03 21:06:54 +02:00
|
|
|
|
2005-10-07 06:40:59 +02:00
|
|
|
#endif /* SOCKET_H */
|