1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
// **********************************************************************
//
// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#ifndef ICE_CONNECTION_I_H
#define ICE_CONNECTION_I_H
#include <IceUtil/Mutex.h>
#include <IceUtil/Monitor.h>
#include <IceUtil/Time.h>
#include <IceUtil/Thread.h> // For ThreadPerConnection.
#include <Ice/Connection.h>
#include <Ice/ConnectionIF.h>
#include <Ice/ConnectionFactoryF.h>
#include <Ice/InstanceF.h>
#include <Ice/TransceiverF.h>
#include <Ice/ObjectAdapterF.h>
#include <Ice/ServantManagerF.h>
#include <Ice/EndpointF.h>
#include <Ice/LoggerF.h>
#include <Ice/TraceLevelsF.h>
#include <Ice/OutgoingAsyncF.h>
#include <Ice/EventHandler.h>
namespace IceInternal
{
class Outgoing;
}
namespace Ice
{
class LocalException;
class ConnectionI : public Connection, public IceInternal::EventHandler, public IceUtil::Monitor<IceUtil::Mutex>
{
public:
void validate();
enum DestructionReason
{
ObjectAdapterDeactivated,
CommunicatorDestroyed
};
void activate();
void hold();
void destroy(DestructionReason);
virtual void close(bool); // From Connection.
bool isDestroyed() const;
bool isFinished() const;
void waitUntilHolding() const;
void waitUntilFinished(); // Not const, as this might close the connection upon timeout.
void monitor();
void prepareRequest(IceInternal::BasicStream*);
void sendRequest(IceInternal::BasicStream*, IceInternal::Outgoing*, bool);
void sendAsyncRequest(IceInternal::BasicStream*, const IceInternal::OutgoingAsyncPtr&, bool);
void prepareBatchRequest(IceInternal::BasicStream*);
void finishBatchRequest(IceInternal::BasicStream*, bool);
void abortBatchRequest();
virtual void flushBatchRequests(); // From Connection.
void sendResponse(IceInternal::BasicStream*, Byte);
void sendNoResponse();
IceInternal::EndpointPtr endpoint() const;
virtual void setAdapter(const ObjectAdapterPtr&); // From Connection.
virtual ObjectAdapterPtr getAdapter() const; // From Connection.
virtual ObjectPrx createProxy(const Identity& ident) const; // From Connection.
//
// Operations from EventHandler
//
virtual bool datagram() const;
virtual bool readable() const;
virtual void read(IceInternal::BasicStream&);
virtual void message(IceInternal::BasicStream&, const IceInternal::ThreadPoolPtr&);
virtual void finished(const IceInternal::ThreadPoolPtr&);
virtual void exception(const LocalException&);
virtual std::string type() const; // From Connection.
virtual Ice::Int timeout() const; // From Connection.
virtual std::string toString() const; // From Connection and EvantHandler.
private:
ConnectionI(const IceInternal::InstancePtr&, const IceInternal::TransceiverPtr&,
const IceInternal::EndpointPtr&, const ObjectAdapterPtr&);
virtual ~ConnectionI();
friend class IceInternal::IncomingConnectionFactory;
friend class IceInternal::OutgoingConnectionFactory;
enum State
{
StateNotValidated,
StateActive,
StateHolding,
StateClosing,
StateClosed
};
void setState(State, const LocalException&);
void setState(State);
void initiateShutdown() const;
void registerWithPool();
void unregisterWithPool();
static void doCompress(IceInternal::BasicStream&, IceInternal::BasicStream&);
static void doUncompress(IceInternal::BasicStream&, IceInternal::BasicStream&);
void parseMessage(IceInternal::BasicStream&, Int&, Int&, Byte&,
IceInternal::ServantManagerPtr&, ObjectAdapterPtr&, IceInternal::OutgoingAsyncPtr&);
void invokeAll(IceInternal::BasicStream&, Int, Int, Byte,
const IceInternal::ServantManagerPtr&, const ObjectAdapterPtr&);
void run();
class ThreadPerConnection : public IceUtil::Thread
{
public:
ThreadPerConnection(const ConnectionIPtr&);
virtual void run();
private:
ConnectionIPtr _connection;
};
friend class ThreadPerConnection;
// Defined as mutable because "isFinished() const" sets this to 0.
mutable IceUtil::ThreadPtr _threadPerConnection;
IceInternal::TransceiverPtr _transceiver;
const std::string _desc;
const std::string _type;
const IceInternal::EndpointPtr _endpoint;
ObjectAdapterPtr _adapter;
IceInternal::ServantManagerPtr _servantManager;
const LoggerPtr _logger;
const IceInternal::TraceLevelsPtr _traceLevels;
bool _registeredWithPool;
const IceInternal::ThreadPoolPtr _threadPool;
const bool _warn;
const int _acmTimeout;
IceUtil::Time _acmAbsoluteTimeout;
const std::vector<Byte> _requestHdr;
const std::vector<Byte> _requestBatchHdr;
const std::vector<Byte> _replyHdr;
Int _nextRequestId;
std::map<Int, IceInternal::Outgoing*> _requests;
std::map<Int, IceInternal::Outgoing*>::iterator _requestsHint;
struct AsyncRequest
{
IceInternal::OutgoingAsyncPtr p;
IceUtil::Time t;
};
std::map<Int, AsyncRequest> _asyncRequests;
std::map<Int, AsyncRequest>::iterator _asyncRequestsHint;
std::auto_ptr<LocalException> _exception;
IceInternal::BasicStream _batchStream;
bool _batchStreamInUse;
int _batchRequestNum;
bool _batchRequestCompress;
int _dispatchCount;
State _state; // The current state.
IceUtil::Time _stateTime; // The last time when the state was changed.
//
// We have a separate mutex for sending, so that we don't block
// the whole connection when we do a blocking send.
//
IceUtil::Mutex _sendMutex;
};
}
#endif
|