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