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>
|
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 // <<< Thu Jul 3 13:50:29 2003 mdd >>> pep_88
66 /*****************************************************************
67 *
68 * The socket support in pegasus is schizophrenic. Some code uses
69 * an Sint32 (fd) as a socket, while other code uses a pointer to an
70 * MP_Socket, which is kind of a container for either an Sint32 socket
71 * or an SSL socket.
72 *
73 * Then there is also the local socket. (AF_UNIX).
74 *
75 * What we need to make all of this coherent is a general-purpose
76 * socket class that uses polymorphism to provide a good sockets
77 * interface.
78 * Because of what we are planning for the pep_88 connection management
79 mday 1.1.2.1 * code this general-purpose socket class should be reference counted.
80 *
81 *****************************************************************/
82
83 class abstract_socket;
84 class socket_factory;
85
86
87 class PEGASUS_COMMON_LINKAGE pegasus_socket
88 {
89
90 public:
91 pegasus_socket(void);
92 pegasus_socket(socket_factory *);
93 pegasus_socket(abstract_socket *);
94 pegasus_socket(const pegasus_socket& s);
95 ~pegasus_socket(void);
96
97 pegasus_socket& operator=(const pegasus_socket& s);
98 operator Sint32() const;
99
100 mday 1.1.2.1 int socket(int type, int style, int protocol, void *ssl_context = 0);
101
102 Sint32 read(void* ptr, Uint32 size);
103 Sint32 write(const void* ptr, Uint32 size);
104 int close(void);
105 int enableBlocking(void);
106 int disableBlocking(void);
107
108 int getsockname (struct sockaddr *addr, size_t *length_ptr);
109 int bind (struct sockaddr *addr, size_t length);
110
111 // change size_t to size_t for ZOS and windows
112 pegasus_socket accept(struct sockaddr *addr, size_t *length_ptr);
113 int connect (struct sockaddr *addr, size_t length);
114 int shutdown(int how);
115 int listen(int q);
116 int getpeername (struct sockaddr *addr, size_t *length_ptr);
117 int send (void *buffer, size_t size, int flags);
118 int recv (void *buffer, size_t size, int flags);
119 int sendto(void *buffer, size_t size, int flags, struct sockaddr *addr, size_t length);
120 int recvfrom(void *buffer, size_t size, int flags, struct sockaddr *addr, size_t *length_ptr);
121 mday 1.1.2.1 int setsockopt (int level, int optname, void *optval, size_t optlen);
122 int getsockopt (int level, int optname, void *optval, size_t *optlen_ptr);
123
124
125 Boolean incompleteReadOccurred(Sint32 retCode);
126 Boolean is_secure(void);
127 void set_close_on_exec(void);
128
129 const char* get_err_string(void);
130
131 private:
132
133 abstract_socket * _rep;
134
135 };
136
137
138 class PEGASUS_COMMON_LINKAGE socket_factory
139 {
140 public:
141 socket_factory(void)
142 mday 1.1.2.1 {
143 }
144
145 virtual ~socket_factory(void)
146 {
147 }
148
149 virtual abstract_socket *make_socket(void) = 0;
|