]> git.ipfire.org Git - thirdparty/squid.git/blob - tools/purge/socket.hh
SourceFormat Enforcement
[thirdparty/squid.git] / tools / purge / socket.hh
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 // Author: Jens-S. V?ckler <voeckler@rvs.uni-hannover.de>
10 //
11 // File: socket.hh
12 // Sun May 3 1998
13 //
14 // (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme
15 // Universit?t Hannover, Germany
16 //
17 // Books: W. Richard Steven, "Advanced Programming in the UNIX Environment",
18 // Addison-Wesley, 1992.
19 //
20 // Permission to use, copy, modify, distribute, and sell this software
21 // and its documentation for any purpose is hereby granted without fee,
22 // provided that (i) the above copyright notices and this permission
23 // notice appear in all copies of the software and related documentation,
24 // and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte
25 // Systeme and the University of Hannover may not be used in any
26 // advertising or publicity relating to the software without the
27 // specific, prior written permission of Lehrgebiet Rechnernetze und
28 // Verteilte Systeme and the University of Hannover.
29 //
30 // THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
31 // EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
32 // WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
33 //
34 // IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR
35 // THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
36 // INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
37 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
38 // ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
39 // ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
40 // SOFTWARE.
41 //
42 // Revision 1.3 1999/01/19 11:00:50 voeckler
43 // added bool type workaround.
44 //
45 // Revision 1.2 1998/08/27 15:23:24 voeckler
46 // added TCP_NODELAY options at several places.
47 //
48 // Revision 1.1 1998/08/13 21:52:55 voeckler
49 // Initial revision
50 //
51 //
52 #ifndef _SOCKET_HH
53 #define _SOCKET_HH
54
55 #if !defined(__cplusplus)
56 #ifndef HAVE_BOOL
57 #define HAVE_BOOL
58 typedef int bool;
59 #define false 0
60 #define true 1
61 #endif
62 #endif /* __cplusplus */
63
64 #include <sys/types.h>
65 #include <sys/socket.h>
66 #include <netinet/in.h>
67
68 #if SOMAXCONN <= 5
69 #undef SOMAXCONN
70 #endif
71
72 #ifndef SOMAXCONN
73 #if defined(SOLARIS)
74 #if MAJOR < 5
75 #define SOMAXCONN 32
76 #else
77 #define SOMAXCONN 128
78 #endif
79 #elif defined(LINUX)
80 #define SOMAXCONN 128
81 #else
82 #define SOMAXCONN 5 // BSD
83 #endif // OS selection
84 #endif // !SOMAXCONN
85
86 #ifndef SA
87 #define SA struct sockaddr
88 #endif
89
90 int
91 setSocketBuffers( int fd, int size );
92 // purpose: set socket buffers for both directions to the specified size
93 // paramtr: size (IN): new socket buffer size
94 // returns: -1 on setsockopt() errors, 0 otherwise
95 // warning: prints error message on stderr, errno will be changed
96
97 int
98 getSocketNoDelay( int sockfd );
99 // purpose: get state of the TCP_NODELAY of the socket
100 // paramtr: sockfd (IN): socket descriptor
101 // returns: 1, if TCP_NODELAY is set,
102 // 0, if TCP_NODELAY is not set,
103 // -1, if an error occurred (e.g. datagram socket)
104
105
106 int
107 setSocketNoDelay( int sockfd, bool nodelay = true );
108 // purpose: get state of the TCP_NODELAY of the socket
109 // paramtr: sockfd (IN): socket descriptor
110 // nodelay (IN): true, if TCP_NODELAY is to be set, false otherwise.
111 // returns: 0, if everything worked out o.k.
112 // -1, if an error occurred (e.g. datagram socket)
113
114 int
115 connectTo( struct in_addr host, unsigned short port, bool nodelay = false,
116 int sendBufferSize = -1, int recvBufferSize = -1 );
117 // purpose: connect to a server as a client
118 // paramtr: host (IN): address describing the server
119 // port (IN): port to connect at the server
120 // nodelay (IN): true=set TCP_NODELAY option.
121 // sendBufferSize (IN): don't set (use sys defaults) if < 0
122 // recvBufferSize (IN): don't set (use sys defaults) if < 0
123 // returns: >=0 is the descriptor of the opened, connected socket,
124 // -1 is an indication of an error (errno may have been reset).
125
126 int
127 serverSocket( struct in_addr host, unsigned short port,
128 int backlog = SOMAXCONN, bool reuse = true, bool nodelay = false,
129 int sendBufferSize = -1, int recvBufferSize = -1 );
130 // purpose: open a server socket for listening
131 // paramtr: host (IN): host to bind locally to, use INADDRY_ANY for *
132 // port (IN): port to bind to, use 0 for system assigned
133 // backlog (IN): listen backlog queue length
134 // reuse (IN): set SO_REUSEADDR option - default usefully
135 // nodelay (IN): true=set TCP_NODELAY option.
136 // SETTING TCP_NODELAY ON A SERVER SOCKET DOES NOT MAKE SENSE!
137 // sendBufferSize (IN): don't set (use sys defaults) if < 0
138 // recvBufferSize (IN): don't set (use sys defaults) if < 0
139 // returns: opened listening fd, or -1 on error.
140 // warning: error message will be printed on stderr and errno reset.
141
142 #endif // _SOCKET_HH