aboutsummaryrefslogtreecommitdiff
path: root/src/unix.h
blob: e317b06be5c9caf4ab9dc5f331bcef4d00c3e838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef COMPAT_H_
#define COMPAT_H_

#include "lspriv.h"

/*=========================================================================*\
* BSD include files
\*=========================================================================*/
/* error codes */
#include <errno.h>
/* close function */
#include <unistd.h>
/* fnctnl function and associated constants */
#include <fcntl.h>
/* struct timeval and CLK_TCK */
#include <sys/time.h>
/* times function and struct tms */
#include <sys/times.h>
/* struct sockaddr */
#include <sys/types.h>
/* socket function */
#include <sys/socket.h>
/* gethostbyname and gethostbyaddr functions */
#include <netdb.h>
/* sigpipe handling */
#include <signal.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#define COMPAT_FD int
#define COMPAT_INVALIDFD (-1)

/* we are lazy... */
typedef struct sockaddr SA;

/*=========================================================================*\
* Exported functions
\*=========================================================================*/
void compat_open(lua_State *L);

#define compat_bind bind
#define compat_connect connect
#define compat_listen listen
#define compat_close close
#define compat_select select

COMPAT_FD compat_socket(int domain, int type, int protocol);
COMPAT_FD compat_accept(COMPAT_FD s, SA *addr, socklen_t *len, int deadline);
int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *done, 
        int deadline);
int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *done, 
        int deadline);
int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *done,
        int deadline, SA *addr, socklen_t len);
int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, 
        int deadline, SA *addr, socklen_t *len);
void compat_setnonblocking(COMPAT_FD sock);
void compat_setblocking(COMPAT_FD sock);
void compat_setreuseaddr(COMPAT_FD sock);

const char *compat_hoststrerror(void);
const char *compat_socketstrerror(void);
const char *compat_bindstrerror(void);
const char *compat_connectstrerror(void);

cchar *compat_trysetoptions(lua_State *L, COMPAT_FD sock);

#endif /* COMPAT_H_ */