jsocketoptions.h
8.38 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/***************************************************************************
* Copyright (C) 2005 by Jeff Ferr *
* root@sat *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef J_SOCKETOPTION_H
#define J_SOCKETOPTION_H
#include "jconnection.h"
#include <string>
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#endif
namespace jsocket {
class Socket;
class Socket6;
class DatagramSocket;
class DatagramSocket6;
class SSLSocket;
class SSLSocket6;
class MulticastSocket;
class MulticastSocket6;
class LocalSocket;
class LocalDatagramSocket;
/**
* \brief
*
*/
enum socket_shutdown_t {
#ifdef _WIN32
SHUTDOWN_READ = 0,
SHUTDOWN_WRITE = 1,
SHUTDOWN_READ_WRITE = 2
#else
SHUTDOWN_READ = SHUT_RD,
SHUTDOWN_WRITE = SHUT_WR,
SHUTDOWN_READ_WRITE = SHUT_RDWR
#endif
};
/**
* \brief SocketOptionss.
*
* \author Jeff Ferr
*/
class SocketOptions : public virtual jcommon::Object{
friend class Socket;
friend class Socket6;
friend class DatagramSocket;
friend class DatagramSocket6;
friend class SSLSocket;
friend class SSLSocket6;
friend class MulticastSocket;
friend class MulticastSocket6;
friend class RawSocket;
friend class SocketPipe;
friend class PromiscSocket;
friend class LocalSocket;
friend class LocalDatagramSocket;
private:
/** \brief Socket handler. */
jsocket_t _fd;
/** \brief Type of socket */
jconnection_type_t _type;
/**
* \brief
*
*/
SocketOptions(jsocket_t fd_, jconnection_type_t type_);
public:
/**
* \brief Virtual destructor
*
*/
virtual ~SocketOptions();
/**
* \brief Enable sending of keep-alive messages on connection-oriented sockets.
*
*/
void SetKeepAlive(bool b_);
/**
* \brief If this option is enabled, out-of-band data is directly placed into the receive data stream.
* Otherwise out-of-band data is only passed when the MSG_OOB flag is set during receiving.
*
*/
void SetOutOfBandInLine(bool b_);
/**
* \brief Specify the sending or receiving timeouts until reporting an error.
* They are fixed to a protocol specific setting in Linux and cannot be read or written.
*
*/
void SetSendTimeout(int time_);
/**
* \brief Specify the sending or receiving timeouts until reporting an error.
* They are fixed to a protocol specific setting in Linux and cannot be read or written.
*
*/
void SetReceiveTimeout(int time_);
/**
* \brief Enable or disable the receiving of the SCM_CREDENTIALS control message.
*
*/
void SetPassCredentials(bool opt_);
/**
* \brief Return the credentials of the foreign process connected to this socket.
*
*/
void GetPeerCredentials(void *opt);
/**
* \brief Bind this socket to a particular device like "eth0", as specified in the passed
* interface name. If the name is an empty string or the option length is zero,
* the socket device binding is removed.
*
*/
void BindToDevice(std::string dev_);
/**
* \brief Indicates that the rules used in validating addresses supplied in a bind call
* should allow reuse of local addresses. For PF_INET sockets this means that a socket
* may bind, except when there is an active listening socket bound to the address. When
* the listening socket is bound to INADDR_ANY with a specific port then it is not possible
* to bind to this port for any local address.
*
*/
void SetReuseAddress(bool opt_);
/**
* \brief
*
*/
void SetReusePort(bool opt_);
/**
* \brief Gets the socket type
*
*/
virtual jconnection_type_t GetType();
/**
* \brief Returns a value indicating whether or not this socket has been marked to accept
* connections with listen.
*
*/
bool GetSocketAcceptConnection();
/**
* \brief Don't send via a gateway, only send to directly connected hosts.
*
*/
void SetRoute(bool opt_);
/**
* \brief Set or get the broadcast flag. When enabled, datagram sockets receive packets
* sent to a broadcast address and they are allowed to send packets to a broadcast
* address. This option has no effect on stream-oriented sockets.
*
*/
void SetBroadcast(bool opt_);
/**
* \brief
*
*/
void SetNoDelay(bool b_);
/**
* \brief Sets or gets the maximum socket send buffer in bytes
*
*/
void SetSendMaximumBuffer(int length_);
/**
* \brief Sets or gets the maximum socket receive buffer in bytes.
*
*/
void SetReceiveMaximumBuffer(int length_);
/**
* \brief Sets or gets the maximum socket send buffer in bytes.
*
*/
int GetSendMaximumBuffer();
/**
* \brief Sets or gets the maximum socket receive buffer in bytes.
*
*/
int GetReceiveMaximumBuffer();
/**
* \brief When enabled, a close() or shutdown() will not return until all queued messages
* for the socket have been successfully sent or the linger timeout has been reached.
* Otherwise, the call returns immediately and the closing is done in the background.
* When the socket is closed as part of exit(), it always lingers in the background.
*
*/
void SetLinger(bool on_, int linger_);
/**
* \brief Set the protocol-defined priority for all packets to be sent on this socket.
* Linux uses this value to order the networking queues:
* packets with a higher priority may be processed first depending on the selected device
* queueing discipline.
*
*/
void SetPriority(int opt_);
/**
* \brief Get and clear the pending socket error.
*
*/
void ClearPendingSocketError();
/**
* \brief /usr/include/linux/ip.h
*
*/
void SetTypeOfService(int type_);
/**
* \brief Throw signal EAGAIN set timeoutexception exception.
*
*/
void SetBlocking(bool opt_);
/**
* \brief Set TTL
*
*/
void SetTimeToLive(int opt_);
/**
* \brief Header is included ?
*
*/
void SetHeaderInclude(bool opt_);
/**
* \brief Return the receive timestamp of the last packet passed to the user.
* This is useful for accurate round trip time measurements.
*
*/
int64_t GetTimeStamp();
/**
* \brief Get MTU.
*
*/
int GetMaximunTransferUnit();
/**
* \brief Change the O_ASYNC flag to enable or disable asynchronous IO mode of the socket.
* Asynchronous IO mode means that the SIGIO signal or the signal set with F_SETSIG is raised
* when a new I/O event occurs.
*
*/
void SetIOAsync(bool opt_);
/**
* \brief
*
*/
void SetMulticastLoop(bool opt_);
/**
* \brief -1 enabled nomal multicast forwarding
*
*/
void SetRSVP(int opt_);
/**
* \brief
*
*/
void SetShutdown(socket_shutdown_t opt_);
/**
* \brief
*
*/
void SetIPv6UnicastHops(int opt_);
/**
* \brief
*
*/
int GetIPv6UnicastHops();
/**
* \brief
*
*/
void SetIPv6Only(bool opt_);
};
}
#endif