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