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