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 kumpf 1.13 #include <Pegasus/Common/Linkage.h>
|
47 mike 1.2
48 PEGASUS_NAMESPACE_BEGIN
49
|
50 mday 1.12 class HTTPConnector;
51
|
52 mday 1.3 class MessageQueueService;
|
53 mike 1.2 struct HTTPConnectionRep;
54
55 /** This message is sent from a connection to its owner (so that the
56 owner can do any necessary cleanup).
57 */
58 class CloseConnectionMessage : public Message
59 {
|
60 mday 1.3 public:
|
61 mike 1.2
|
62 mday 1.4 CloseConnectionMessage(Sint32 socket_)
63 : Message(CLOSE_CONNECTION_MESSAGE), socket(socket_) { }
|
64 mike 1.2
|
65 mday 1.4 Sint32 socket;
|
66 mike 1.2 };
67
68 /** This class represents an HTTP listener.
69 */
|
70 mday 1.15 class Monitor;
71
|
72 mday 1.5 class PEGASUS_COMMON_LINKAGE HTTPConnection : public MessageQueue
|
73 mike 1.2 {
|
74 mday 1.3 public:
|
75 mday 1.5 typedef MessageQueue Base;
|
76 mday 1.3
|
77 mday 1.4 /** Constructor. */
78 HTTPConnection(
79 Monitor* monitor,
80 //Sint32 socket,
81 MP_Socket * socket,
|
82 mday 1.8 MessageQueue * ownerMessageQueue,
83 MessageQueue * outputMessageQueue);
84
|
85 mday 1.4
86 /** Destructor. */
87 ~HTTPConnection();
88
89 /** This method is called whenever a SocketMessage is enqueued
90 on the input queue of the HTTPConnection object.
91 */
92 virtual void handleEnqueue(Message *);
93
94 virtual void handleEnqueue();
|
95 mike 1.2
|
96 mday 1.4 /** Return socket this connection is using. */
97 Sint32 getSocket() { return _socket->getSocket();}
|
98 mday 1.12
|
99 mday 1.4 /** Return the number of outstanding requests for all HTTPConnection
100 instances.
101 */
102 Uint32 getRequestCount();
|
103 mday 1.8
104 Boolean run(Uint32 milliseconds);
105
106 void lock_connection(void)
107 {
|
108 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
109 "HTTPConnection::lock_connection - LOCK REQUESTED");
|
110 mday 1.8 _connection_mut.lock(pegasus_thread_self());
|
111 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
112 "HTTPConnection::lock_connection - LOCK ACQUIRED");
|
113 mday 1.8 }
114
115 void unlock_connection(void)
116 {
117 _connection_mut.unlock();
|
118 kumpf 1.10 Tracer::trace(TRC_HTTP, Tracer::LEVEL4,
119 "HTTPConnection::unlock_connection - LOCK RELEASED");
|
120 mday 1.8 }
121
122 Boolean is_dying(void)
123 {
124 if( _dying.value() > 0 )
125 return true;
126 return false;
127 }
|
128 mday 1.7
|
129 mday 1.8 MessageQueue & get_owner(void)
130 {
131 return *_ownerMessageQueue;
132 }
133
|
134 kumpf 1.9 // ATTN-RK-P1-20020521: This is a major hack, required to get the CIM
135 // server and tests to run successfully. The problem is that the
136 // HTTPAcceptor is deleting an HTTPConnection before all the threads
137 // that are queued up to run in that HTTPConnection instance have had
138 // a chance to finish. This hack makes the HTTPAcceptor spin until
139 // the HTTPConnection event threads have completed, before deleting
140 // the HTTPConnection. Note that this fix is not perfect, because
141 // there is a window between when the HTTPConnection queue lookup is
142 // done and when the refcount is incremented. If the HTTPAcceptor
143 // deletes the HTTPConnection in that window, the soon-to-be-launched
144 // HTTPConnection event thread will fail (hard).
145 AtomicInt refcount;
|
146 mday 1.8
|
147 mday 1.4 private:
|
148 mike 1.2
|
149 mday 1.4 void _clearIncoming();
|
150 mike 1.2
|
151 mday 1.4 void _getContentLengthAndContentOffset();
|
152 mike 1.2
|
153 mday 1.4 void _closeConnection();
|
154 mike 1.2
|
155 mday 1.4 void _handleReadEvent();
|
156 mike 1.2
|
157 mday 1.4 Monitor* _monitor;
|
158 mike 1.2
|
159 mday 1.4 //Sint32 _socket;
160 MP_Socket* _socket;
|
161 mday 1.8 MessageQueue* _ownerMessageQueue;
162 MessageQueue* _outputMessageQueue;
|
163 mike 1.2
|
164 mday 1.4 Sint32 _contentOffset;
165 Sint32 _contentLength;
166 Array<Sint8> _incomingBuffer;
167 AuthenticationInfo* _authInfo;
168 static AtomicInt _requestCount;
|
169 mday 1.8 Mutex _connection_mut;
170 AtomicInt _dying;
|
171 mday 1.12 int _entry_index;
172
173 friend class Monitor;
174 friend class HTTPAcceptor;
175 friend class HTTPConnector;
|
176 mike 1.2 };
177
178 PEGASUS_NAMESPACE_END
179
180 #endif /* Pegasus_HTTPConnection_h */
|