1 karl 1.9 //%2003////////////////////////////////////////////////////////////////////////
|
2 mday 1.2 //
|
3 karl 1.9 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mday 1.2 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Day (mdday@us.ibm.com)
27 //
28 mday 1.2 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 #ifndef peg_socket_class_heirarchy_h
34 #define peg_socket_class_heirarchy_h
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/IPC.h>
38 #include <Pegasus/Common/TLS.h>
39 #ifdef PEGASUS_OS_TYPE_WINDOWS
40 #include <windows.h>
41 # ifndef _WINSOCKAPI_
42 # include <winsock2.h>
43 # endif
44 #else
45 # include <cctype>
46 #ifndef PEGASUS_OS_OS400
|
47 mday 1.4 //# include <unistd.h>
|
48 mday 1.2 #else
49 # include <Pegasus/Common/OS400ConvertChar.h>
50 # include <unistd.cleinc>
51 #endif
52 #ifdef PEGASUS_OS_ZOS
53 # include <string.h> // added by rk for memcpy
54 #endif
55 # include <cstdlib>
56 # include <errno.h>
57 # include <fcntl.h>
58 # include <netdb.h>
59 # include <netinet/in.h>
60 # include <arpa/inet.h>
61 # include <sys/socket.h>
62 #endif
|
63 marek 1.7 #ifdef PEGASUS_OS_ZOS
64 # include <Pegasus/Common/SocketzOS_inline.h>
65 #endif
|
66 mday 1.2 #include <Pegasus/Common/Linkage.h>
67
68 PEGASUS_NAMESPACE_BEGIN
69
70 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
71 typedef size_t PEGASUS_SOCKLEN_SIZE;
72
|
73 keith.petley 1.8 #elif defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || (defined(PEGASUS_OS_SOLARIS) && !defined(SUNOS_5_6))
|
74 mday 1.2 typedef socklen_t PEGASUS_SOCKLEN_SIZE;
75 #else
|
76 mday 1.4 typedef int PEGASUS_SOCKLEN_SIZE;
|
77 mday 1.2 #endif
78
79
80
81
82 // <<< Thu Jul 3 13:50:29 2003 mdd >>> pep_88
83 /*****************************************************************
84 *
85 * The socket support in pegasus is schizophrenic. Some code uses
86 * an Sint32 (fd) as a socket, while other code uses a pointer to an
87 * MP_Socket, which is kind of a container for either an Sint32 socket
88 * or an SSL socket.
89 *
90 * Then there is also the local socket. (AF_UNIX).
91 *
92 * What we need to make all of this coherent is a general-purpose
93 * socket class that uses polymorphism to provide a good sockets
94 * interface.
95 * Because of what we are planning for the pep_88 connection management
96 * code this general-purpose socket class should be reference counted.
97 *
98 mday 1.2 *****************************************************************/
99
100 class abstract_socket;
101 class socket_factory;
102
103
104 class PEGASUS_COMMON_LINKAGE pegasus_socket
105 {
106
|
107 mday 1.3 public:
108
109 pegasus_socket(void);
110 pegasus_socket(socket_factory *);
|
111 konrad.r 1.10 pegasus_socket(socket_factory *, SSLContext *);
|
112 mday 1.3 pegasus_socket(abstract_socket *);
113 pegasus_socket(const pegasus_socket& s);
114 ~pegasus_socket(void);
|
115 mday 1.2
|
116 mday 1.3 pegasus_socket& operator=(const pegasus_socket& s);
117 Boolean operator==(const pegasus_socket& s);
118
119 operator Sint32() const;
|
120 mday 1.2
|
121 mday 1.3 int socket(int type, int style, int protocol, void *ssl_context = 0);
|
122 mday 1.2
|
123 mday 1.3 Sint32 read(void* ptr, Uint32 size);
124 Sint32 write(const void* ptr, Uint32 size);
125 int close(void);
126 int enableBlocking(void);
127 int disableBlocking(void);
|
128 mday 1.2
|
129 mday 1.3 int getsockname (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
130 int bind (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
|
131 mday 1.2
|
132 mday 1.3 // change size_t to size_t for ZOS and windows
133 pegasus_socket accept(struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
134 int connect (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
135 int shutdown(int how);
136 int listen(int q);
137 int getpeername (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
138 int send (void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags);
139 int recv (void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags);
140 int sendto(void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags, struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
141 int recvfrom(void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags, struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
142 int setsockopt (int level, int optname, void *optval, PEGASUS_SOCKLEN_SIZE optlen);
143 int getsockopt (int level, int optname, void *optval, PEGASUS_SOCKLEN_SIZE *optlen_ptr);
144
145
146 Boolean incompleteReadOccurred(Sint32 retCode);
147 Boolean is_secure(void);
|
148 mday 1.5 void set_close_on_exec(void);
|
149 mday 1.2
|
150 mday 1.3 const char* get_err_string(void);
151
152 private:
|
153 mday 1.2
|
154 mday 1.3 abstract_socket * _rep;
|
155 mday 1.2
156 };
157
158
159 class PEGASUS_COMMON_LINKAGE socket_factory
160 {
|
161 mday 1.3 public:
162 socket_factory(void)
163 {
164 }
|
165 mday 1.2
|
166 mday 1.3 virtual ~socket_factory(void)
167 {
168 }
|
169 mday 1.2
|
170 mday 1.3 virtual abstract_socket *make_socket(void) = 0;
|
171 mday 1.2 #ifdef PEGASUS_HAS_SSL
|
172 mday 1.3 virtual abstract_socket *make_socket(SSLContext *) = 0;
|
173 mday 1.2 #endif
174 };
175
176
177
178 /**
179 * factory class for creating the bsd socket object
180 **/
181 class PEGASUS_COMMON_LINKAGE bsd_socket_factory : public socket_factory
182 {
|
183 mday 1.3 public:
184 bsd_socket_factory(void);
185 ~bsd_socket_factory(void);
186 abstract_socket *make_socket(void);
|
187 mday 1.2 #ifdef PEGASUS_HAS_SSL
|
188 mday 1.3 abstract_socket *make_socket(SSLContext* );
|
189 mday 1.2 #endif
190 };
191
192
193
194 #ifdef PEGASUS_HAS_SSL
195
196 class PEGASUS_COMMON_LINKAGE ssl_socket_factory : public socket_factory
197 {
198
|
199 mday 1.3 public:
200 ssl_socket_factory(void);
201 ~ssl_socket_factory(void);
202 abstract_socket* make_socket(void);
203 abstract_socket* make_socket(SSLContext* );
|
204 mday 1.2 };
205
206
207
208 #endif
209
210
211 # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
212 // << Thu Aug 14 15:01:30 2003 mdd >> domain sockets work
213 class PEGASUS_COMMON_LINKAGE unix_socket_factory : public socket_factory
214 {
|
215 mday 1.3 public:
216 unix_socket_factory(void);
217 ~unix_socket_factory(void);
218 abstract_socket* make_socket(void);
|
219 kumpf 1.6 #ifdef PEGASUS_HAS_SSL
220 abstract_socket *make_socket(SSLContext*); // Do not use
221 #endif
|
222 mday 1.2 };
223
224
225 #endif
226
227 PEGASUS_NAMESPACE_END
228
229 #endif /* peg_socket_class_heirarchy_h */
|