2003-06-26 11:47:49 -07:00
|
|
|
#ifndef SOCK_H
|
|
|
|
#define SOCK_H
|
2003-03-28 13:08:50 -08:00
|
|
|
/*=========================================================================*\
|
2003-05-24 18:56:46 -07:00
|
|
|
* Socket compatibilization module
|
2003-06-26 11:47:49 -07: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 13:08:50 -08:00
|
|
|
*
|
2003-05-24 18:56:46 -07:00
|
|
|
* RCS ID: $Id$
|
2003-03-28 13:08:50 -08:00
|
|
|
\*=========================================================================*/
|
2003-06-09 11:23:40 -07:00
|
|
|
#include "io.h"
|
2002-07-03 12:06:54 -07:00
|
|
|
|
2003-05-24 18:56:46 -07:00
|
|
|
/*=========================================================================*\
|
|
|
|
* Platform specific compatibilization
|
|
|
|
\*=========================================================================*/
|
2004-06-16 17:18:48 -07:00
|
|
|
#ifdef _WIN32
|
2003-06-09 11:23:40 -07:00
|
|
|
#include "wsocket.h"
|
2003-05-24 18:56:46 -07:00
|
|
|
#else
|
2003-06-09 11:23:40 -07:00
|
|
|
#include "usocket.h"
|
2003-05-24 18:56:46 -07:00
|
|
|
#endif
|
|
|
|
|
2004-01-21 10:40:52 -08: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-24 18:56:46 -07:00
|
|
|
/* we are lazy... */
|
|
|
|
typedef struct sockaddr SA;
|
|
|
|
|
|
|
|
/*=========================================================================*\
|
|
|
|
* Functions bellow implement a comfortable platform independent
|
|
|
|
* interface to sockets
|
|
|
|
\*=========================================================================*/
|
2003-06-09 11:23:40 -07:00
|
|
|
int sock_open(void);
|
2004-05-30 14:36:22 -07:00
|
|
|
int sock_close(void);
|
2003-05-24 18:56:46 -07:00
|
|
|
void sock_destroy(p_sock ps);
|
2004-01-15 23:06:31 -08:00
|
|
|
void sock_shutdown(p_sock ps, int how);
|
2003-05-24 18:56:46 -07:00
|
|
|
int sock_sendto(p_sock ps, const char *data, size_t count,
|
2004-06-30 20:32:09 -07:00
|
|
|
size_t *sent, SA *addr, socklen_t addr_len, p_tm tm);
|
2003-05-24 18:56:46 -07:00
|
|
|
int sock_recvfrom(p_sock ps, char *data, size_t count,
|
2004-06-30 20:32:09 -07:00
|
|
|
size_t *got, SA *addr, socklen_t *addr_len, p_tm tm);
|
2005-02-08 02:01:01 -08:00
|
|
|
|
2003-05-24 18:56:46 -07:00
|
|
|
void sock_setnonblocking(p_sock ps);
|
|
|
|
void sock_setblocking(p_sock ps);
|
2005-02-08 02:01:01 -08:00
|
|
|
|
2005-03-10 16:20:21 -08:00
|
|
|
int sock_waitfd(p_sock ps, int sw, p_tm tm);
|
2004-06-30 20:32:09 -07:00
|
|
|
int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm);
|
2004-01-23 16:18:19 -08:00
|
|
|
|
2004-07-14 23:11:53 -07:00
|
|
|
int sock_connect(p_sock ps, SA *addr, socklen_t addr_len, 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);
|
|
|
|
int sock_accept(p_sock ps, p_sock pa, SA *addr, socklen_t *addr_len, p_tm tm);
|
|
|
|
|
|
|
|
const char *sock_hoststrerror(int err);
|
|
|
|
const char *sock_strerror(int err);
|
|
|
|
|
|
|
|
/* these are perfect to use with the io abstraction module
|
|
|
|
and the buffered input module */
|
|
|
|
int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm);
|
|
|
|
int sock_recv(p_sock ps, char *data, size_t count, size_t *got, p_tm tm);
|
|
|
|
const char *sock_ioerror(p_sock ps, int err);
|
2004-01-23 16:18:19 -08:00
|
|
|
|
2004-07-14 23:11:53 -07:00
|
|
|
int sock_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
|
|
|
|
int sock_gethostbyname(const char *addr, struct hostent **hp);
|
2002-07-03 12:06:54 -07:00
|
|
|
|
2003-05-24 18:56:46 -07:00
|
|
|
#endif /* SOCK_H */
|