1 kumpf 1.11 //%/////////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 kumpf 1.11 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
|
4 mike 1.2 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.11 // 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 mike 1.2 // 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 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.2 // 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 kumpf 1.11 // 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 mike 1.2 // 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 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By:
27 // Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
28 // Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_HTTPConnection_h
33 #define Pegasus_HTTPConnection_h
34
35 #include <iostream>
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/MessageQueue.h>
38 #include <Pegasus/Common/Pair.h>
39 #include <Pegasus/Common/String.h>
40 mike 1.2 #include <Pegasus/Common/Message.h>
|
41 kumpf 1.14 #include <Pegasus/Common/ArrayInternal.h>
|
42 mike 1.2 #include <Pegasus/Common/Monitor.h>
43 #include <Pegasus/Common/AuthenticationInfo.h>
44 #include <Pegasus/Common/TLS.h>
45 #include <Pegasus/Common/HTTPAcceptor.h>
|
46 mday 1.16 #include <Pegasus/Common/pegasus_socket.h>
|
47 kumpf 1.13 #include <Pegasus/Common/Linkage.h>
|
48 mike 1.2
49 PEGASUS_NAMESPACE_BEGIN
50
|
51 mday 1.12 class HTTPConnector;
52
|
53 mday 1.3 class MessageQueueService;
|
54 mday 1.16
|
55 mike 1.2 struct HTTPConnectionRep;
56
57 /** This message is sent from a connection to its owner (so that the
58 owner can do any necessary cleanup).
59 */
60 class CloseConnectionMessage : public Message
61 {
|
62 mday 1.3 public:
|
63 mike 1.2
|
64 mday 1.4 CloseConnectionMessage(Sint32 socket_)
65 : Message(CLOSE_CONNECTION_MESSAGE), socket(socket_) { }
|
66 mike 1.2
|
67 mday 1.4 Sint32 socket;
|
68 mike 1.2 };
69
70 /** This class represents an HTTP listener.
71 */
|
72 mday 1.15 class Monitor;
73
|
74 mday 1.5 class PEGASUS_COMMON_LINKAGE HTTPConnection : public MessageQueue
|
75 mike 1.2 {
|
76 mday 1.3 public:
|
77 mday 1.5 typedef MessageQueue Base;
|
78 mday 1.3
|
79 mday 1.4 /** Constructor. */
80 HTTPConnection(
81 Monitor* monitor,
82 //Sint32 socket,
83 MP_Socket * socket,
|
84 mday 1.8 MessageQueue * ownerMessageQueue,
85 MessageQueue * outputMessageQueue);
86
|
87 mday 1.4
88 /** Destructor. */
89 ~HTTPConnection();
90
91 /** This method is called whenever a SocketMessage is enqueued
92 on the input queue of the HTTPConnection object.
93 */
94 virtual void handleEnqueue(Message *);
95
96 virtual void handleEnqueue();
|
97 mike 1.2
|
98 mday 1.4 /** Return socket this connection is using. */
99 Sint32 getSocket() { return _socket->getSocket();}
|
100 mday 1.12
|
101 mday 1.4 /** Return the number of outstanding requests for all HTTPConnection
102 instances.
103 */
104 Uint32 getRequestCount();
|
105 mday 1.8
106 Boolean run(Uint32 milliseconds);
107
108 void lock_connection(void)
109 {
|
110 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
111 "HTTPConnection::lock_connection - LOCK REQUESTED");
|
112 mday 1.8 _connection_mut.lock(pegasus_thread_self());
|
113 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
114 "HTTPConnection::lock_connection - LOCK ACQUIRED");
|
115 mday 1.8 }
116
117 void unlock_connection(void)
118 {
119 _connection_mut.unlock();
|
120 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
121 "HTTPConnection::unlock_connection - LOCK RELEASED");
|
122 mday 1.8 }
123
124 Boolean is_dying(void)
125 {
126 if( _dying.value() > 0 )
127 return true;
128 return false;
129 }
|
130 mday 1.7
|
131 mday 1.8 MessageQueue & get_owner(void)
132 {
133 return *_ownerMessageQueue;
134 }
135
|
136 kumpf 1.9 // ATTN-RK-P1-20020521: This is a major hack, required to get the CIM
137 // server and tests to run successfully. The problem is that the
138 // HTTPAcceptor is deleting an HTTPConnection before all the threads
139 // that are queued up to run in that HTTPConnection instance have had
140 // a chance to finish. This hack makes the HTTPAcceptor spin until
141 // the HTTPConnection event threads have completed, before deleting
142 // the HTTPConnection. Note that this fix is not perfect, because
143 // there is a window between when the HTTPConnection queue lookup is
144 // done and when the refcount is incremented. If the HTTPAcceptor
145 // deletes the HTTPConnection in that window, the soon-to-be-launched
146 // HTTPConnection event thread will fail (hard).
147 AtomicInt refcount;
|
148 mday 1.8
|
149 mday 1.4 private:
|
150 mike 1.2
|
151 mday 1.4 void _clearIncoming();
|
152 mike 1.2
|
153 mday 1.4 void _getContentLengthAndContentOffset();
|
154 mike 1.2
|
155 mday 1.4 void _closeConnection();
|
156 mike 1.2
|
157 mday 1.4 void _handleReadEvent();
|
158 mike 1.2
|
159 mday 1.4 Monitor* _monitor;
|
160 mike 1.2
|
161 mday 1.4 //Sint32 _socket;
162 MP_Socket* _socket;
|
163 mday 1.8 MessageQueue* _ownerMessageQueue;
164 MessageQueue* _outputMessageQueue;
|
165 mike 1.2
|
166 mday 1.4 Sint32 _contentOffset;
167 Sint32 _contentLength;
168 Array<Sint8> _incomingBuffer;
169 AuthenticationInfo* _authInfo;
170 static AtomicInt _requestCount;
|
171 mday 1.8 Mutex _connection_mut;
|
172 kumpf 1.20
173 // ATTN-DE-P2-20030926::TODO::Recommend that the _dying
174 // variable be moved to the MonitorEntry structure (Monitor.h)
175
176 // A non-zero value of _dying indicates that this connection
177 // is being closed and the HTTPConnection structure deleted.
178 // Once this value has been set to a non-zero value, this
179 // connection MUST not be used. Accessing the HTTPConnection
180 // structure after this flag has been set can result in memory
181 // corruption and segmentation faults.
|
182 mday 1.8 AtomicInt _dying;
|
183 kumpf 1.20
184 // The _connectionClosePending flag will be set to true if
185 // the connection receives close connection socket message.
186 // This flag is used to set the _dying value.
187 Boolean _connectionClosePending;
188
|
189 mday 1.12 int _entry_index;
190
191 friend class Monitor;
192 friend class HTTPAcceptor;
193 friend class HTTPConnector;
|
194 mike 1.2 };
|
195 mday 1.16
196 class PEGASUS_COMMON_LINKAGE HTTPConnection2 : public MessageQueue
197 {
198 public:
199 typedef MessageQueue Base;
200
201 /** Constructor. */
202 HTTPConnection2( pegasus_socket socket,
203 MessageQueue * outputMessageQueue);
204
205 /** Destructor. */
206 ~HTTPConnection2();
207
|
208 mday 1.21 virtual void enqueue(Message *) throw(IPCException);
209
|
210 mday 1.16 /** This method is called whenever a SocketMessage is enqueued
211 on the input queue of the HTTPConnection2 object.
212 */
213 virtual void handleEnqueue(Message *);
214
215 virtual void handleEnqueue();
216
217 /** Return socket this connection is using. */
218 Sint32 getSocket();
219
220 /** Return the number of outstanding requests for all HTTPConnection2
221 instances.
222 */
223 Uint32 getRequestCount();
224
225
226
227 AtomicInt refcount;
228
229 Boolean operator ==(const HTTPConnection2& );
230 Boolean operator ==(void*);
|
231 mday 1.17 static void connection_dispatch(monitor_2_entry*);
|
232 mday 1.16
233 private:
234
235 void _clearIncoming();
236
237 void _getContentLengthAndContentOffset();
238
|
239 mday 1.18 void _handleReadEvent(monitor_2_entry* );
|
240 mday 1.16
|
241 mday 1.21 void _close_connection(void);
242
|
243 mday 1.16 pegasus_socket _socket;
244 MessageQueue* _outputMessageQueue;
245
246 Sint32 _contentOffset;
247 Sint32 _contentLength;
248 Array<Sint8> _incomingBuffer;
249 AuthenticationInfo* _authInfo;
|
250 mday 1.21 AtomicInt _closed;
251 Mutex _reentry;
252
253
|
254 mday 1.16 static AtomicInt _requestCount;
255
|
256 mday 1.21 friend class monitor_2;
|
257 mday 1.16 friend class HTTPAcceptor;
258 };
259
|
260 mike 1.2
261 PEGASUS_NAMESPACE_END
262
263 #endif /* Pegasus_HTTPConnection_h */
|
264 mday 1.19
265
266
267 // HINT: - you are not deleting the connection object !!!!!
|