-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockio.h
113 lines (94 loc) · 2.81 KB
/
sockio.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* (C) 2001 Clemson University and The University of Chicago
*
* See COPYING in top-level directory.
*/
/*
* These are the exported functions from the sockio library. They
* provide a simple intuitive interface to the TCP/IP sockets API.
*/
/*
* Defines which may be set at compile time to determine functionality:
*
* __USE_SENDFILE__ turns on the use of sendfile() in the library and
* makes the BMI_sockio_nbsendfile function available to the application.
* Older glibc systems do not have this functionality so we leave it to
* be turned on manually.
*/
#ifndef SOCKIO_H
#define SOCKIO_H
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
int BMI_sockio_new_sock(void);
int BMI_sockio_bind_sock(int,
int);
int BMI_sockio_bind_sock_specific(int sockd,
const char *name,
int service);
int BMI_sockio_connect_sock(int,
const char *,
int,
char *,
int *);
int BMI_sockio_init_sock(struct sockaddr *,
const char *,
int);
int BMI_sockio_nbrecv(int s,
void *buf,
int len);
int BMI_sockio_nbsend(int s,
void *buf,
int len);
int BMI_sockio_nbvector(int s,
struct iovec* vector,
int count,
int recv_flag);
int BMI_sockio_get_sockopt(int s,
int optname);
int BMI_sockio_set_tcpopt(int s,
int optname,
int val);
int BMI_sockio_set_sockopt(int s,
int optname,
int size);
int BMI_sockio_nbpeek(int s,
void* buf,
int len);
#define GET_RECVBUFSIZE(s) BMI_sockio_get_sockopt(s, SO_RCVBUF)
#define GET_SENDBUFSIZE(s) BMI_sockio_get_sockopt(s, SO_SNDBUF)
/* some OS's (ie. Linux 1.3.xx) can't handle buffer sizes of certain
* sizes, and will hang up
*/
#ifdef BRAINDEADSOCKS
/* setting socket buffer sizes can do bad things */
#define SET_RECVBUFSIZE(s, size)
#define SET_SENDBUFSIZE(s, size)
#else
#define SET_RECVBUFSIZE(s, size) BMI_sockio_set_sockopt(s, SO_RCVBUF, size)
#define SET_SENDBUFSIZE(s, size) BMI_sockio_set_sockopt(s, SO_SNDBUF, size)
#endif
#define GET_MINSENDSIZE(s) BMI_sockio_get_sockopt(s, SO_SNDLOWAT)
#define GET_MINRECVSIZE(s) BMI_sockio_get_sockopt(s, SO_RCVLOWAT)
#define SET_MINSENDSIZE(s, size) BMI_sockio_set_sockopt(s, SO_SNDLOWAT, size)
#define SET_MINRECVSIZE(s, size) BMI_sockio_set_sockopt(s, SO_RCVLOWAT, size)
/* BLOCKING / NONBLOCKING MACROS */
#define SET_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, O_NONBLOCK | \
fcntl((x_fd), F_GETFL, 0))
#define SET_NONBLOCK_AND_SIGIO(x_fd) \
do { \
fcntl((x_fd), F_SETOWN, getpid()); \
fcntl((x_fd), F_SETFL, FASYNC | O_NONBLOCK | fcntl((x_fd), F_GETFL, 0)); \
} while (0)
#define CLR_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, fcntl((x_fd), F_GETFL, 0) & \
(~O_NONBLOCK))
#endif
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/