1 //%2003////////////////////////////////////////////////////////////////////////
3 // 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.
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:
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.
24 //==============================================================================
26 // Author: Mike Day (mdday@us.ibm.com)
30 //%/////////////////////////////////////////////////////////////////////////////
33 #ifndef peg_socket_class_heirarchy_h
34 #define peg_socket_class_heirarchy_h
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/IPC.h>
38 #include <Pegasus/Common/TLS.h>
39 #ifdef PEGASUS_OS_TYPE_WINDOWS
42 # include <winsock2.h>
46 #ifndef PEGASUS_OS_OS400
47 //# include <unistd.h>
49 # include <Pegasus/Common/OS400ConvertChar.h>
50 # include <unistd.cleinc>
53 # include <string.h> // added by rk for memcpy
59 # include <netinet/in.h>
60 # include <arpa/inet.h>
61 # include <sys/socket.h>
64 # include <Pegasus/Common/SocketzOS_inline.h>
66 #include <Pegasus/Common/Linkage.h>
68 PEGASUS_NAMESPACE_BEGIN
70 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
71 typedef size_t PEGASUS_SOCKLEN_SIZE;
73 #elif defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || (defined(PEGASUS_OS_SOLARIS) && !defined(SUNOS_5_6))
74 typedef socklen_t PEGASUS_SOCKLEN_SIZE;
76 typedef int PEGASUS_SOCKLEN_SIZE;
82 // <<< Thu Jul 3 13:50:29 2003 mdd >>> pep_88
83 /*****************************************************************
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
90 * Then there is also the local socket. (AF_UNIX).
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
95 * Because of what we are planning for the pep_88 connection management
96 * code this general-purpose socket class should be reference counted.
98 *****************************************************************/
100 class abstract_socket;
101 class socket_factory;
104 class PEGASUS_COMMON_LINKAGE pegasus_socket
109 pegasus_socket(void);
110 pegasus_socket(socket_factory *);
111 pegasus_socket(abstract_socket *);
112 pegasus_socket(const pegasus_socket& s);
113 ~pegasus_socket(void);
115 pegasus_socket& operator=(const pegasus_socket& s);
116 Boolean operator==(const pegasus_socket& s);
118 operator Sint32() const;
120 int socket(int type, int style, int protocol, void *ssl_context = 0);
122 Sint32 read(void* ptr, Uint32 size);
123 Sint32 write(const void* ptr, Uint32 size);
125 int enableBlocking(void);
126 int disableBlocking(void);
128 int getsockname (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
129 int bind (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
131 // change size_t to size_t for ZOS and windows
132 pegasus_socket accept(struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
133 int connect (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
134 int shutdown(int how);
136 int getpeername (struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
137 int send (void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags);
138 int recv (void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags);
139 int sendto(void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags, struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE length);
140 int recvfrom(void *buffer, PEGASUS_SOCKLEN_SIZE size, int flags, struct sockaddr *addr, PEGASUS_SOCKLEN_SIZE *length_ptr);
141 int setsockopt (int level, int optname, void *optval, PEGASUS_SOCKLEN_SIZE optlen);
142 int getsockopt (int level, int optname, void *optval, PEGASUS_SOCKLEN_SIZE *optlen_ptr);
145 Boolean incompleteReadOccurred(Sint32 retCode);
146 Boolean is_secure(void);
147 void set_close_on_exec(void);
149 const char* get_err_string(void);
153 abstract_socket * _rep;
158 class PEGASUS_COMMON_LINKAGE socket_factory
165 virtual ~socket_factory(void)
169 virtual abstract_socket *make_socket(void) = 0;
170 #ifdef PEGASUS_HAS_SSL
171 virtual abstract_socket *make_socket(SSLContext *) = 0;
178 * factory class for creating the bsd socket object
180 class PEGASUS_COMMON_LINKAGE bsd_socket_factory : public socket_factory
183 bsd_socket_factory(void);
184 ~bsd_socket_factory(void);
185 abstract_socket *make_socket(void);
186 #ifdef PEGASUS_HAS_SSL
187 abstract_socket *make_socket(SSLContext* );
193 #ifdef PEGASUS_HAS_SSL
195 class PEGASUS_COMMON_LINKAGE ssl_socket_factory : public socket_factory
199 ssl_socket_factory(void);
200 ~ssl_socket_factory(void);
201 abstract_socket* make_socket(void);
202 abstract_socket* make_socket(SSLContext* );
210 # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
211 // << Thu Aug 14 15:01:30 2003 mdd >> domain sockets work
212 class PEGASUS_COMMON_LINKAGE unix_socket_factory : public socket_factory
215 unix_socket_factory(void);
216 ~unix_socket_factory(void);
217 abstract_socket* make_socket(void);
218 #ifdef PEGASUS_HAS_SSL
219 abstract_socket *make_socket(SSLContext*); // Do not use
226 PEGASUS_NAMESPACE_END
228 #endif /* peg_socket_class_heirarchy_h */