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
|
// **********************************************************************
//
// Copyright (c) 2003
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************
#ifndef ICE_CONNECTION_H
#define ICE_CONNECTION_H
#include <IceUtil/Mutex.h>
#include <IceUtil/Monitor.h>
#include <IceUtil/Time.h>
#include <Ice/ConnectionF.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 Ice
{
class LocalException;
}
namespace IceInternal
{
class Outgoing;
class Connection : public EventHandler, public IceUtil::Monitor<IceUtil::Mutex>
{
public:
void validate();
enum DestructionReason
{
ObjectAdapterDeactivated,
CommunicatorDestroyed
};
void activate();
void hold();
void destroy(DestructionReason);
bool isValidated() const;
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(BasicStream*);
void sendRequest(BasicStream*, Outgoing*);
void sendAsyncRequest(BasicStream*, const OutgoingAsyncPtr&);
void prepareBatchRequest(BasicStream*);
void finishBatchRequest(BasicStream*);
void flushBatchRequest();
void sendResponse(BasicStream*, Ice::Byte);
void sendNoResponse();
int timeout() const;
EndpointPtr endpoint() const;
void setAdapter(const Ice::ObjectAdapterPtr&);
Ice::ObjectAdapterPtr getAdapter() const;
//
// Operations from EventHandler
//
virtual bool datagram() const;
virtual bool readable() const;
virtual void read(BasicStream&);
virtual void message(BasicStream&, const ThreadPoolPtr&);
virtual void finished(const ThreadPoolPtr&);
virtual void exception(const Ice::LocalException&);
virtual std::string toString() const;
//
// Compare endpoints for sorting purposes.
//
virtual bool operator==(const Connection&) const;
virtual bool operator!=(const Connection&) const;
virtual bool operator<(const Connection&) const;
private:
Connection(const InstancePtr&, const TransceiverPtr&, const EndpointPtr&, const Ice::ObjectAdapterPtr&);
virtual ~Connection();
friend class IncomingConnectionFactory;
friend class OutgoingConnectionFactory;
enum State
{
StateNotValidated,
StateActive,
StateHolding,
StateClosing,
StateClosed
};
void setState(State, const Ice::LocalException&);
void setState(State);
void initiateShutdown() const;
void registerWithPool();
void unregisterWithPool();
static void doCompress(BasicStream&, BasicStream&);
static void doUncompress(BasicStream&, BasicStream&);
TransceiverPtr _transceiver;
const std::string _desc;
const EndpointPtr _endpoint;
Ice::ObjectAdapterPtr _adapter;
ServantManagerPtr _servantManager;
const Ice::LoggerPtr _logger;
const TraceLevelsPtr _traceLevels;
bool _registeredWithPool;
const ThreadPoolPtr _threadPool;
const bool _warn;
const int _acmTimeout;
IceUtil::Time _acmAbsoluteTimeout;
const std::vector<Ice::Byte> _requestHdr;
const std::vector<Ice::Byte> _requestBatchHdr;
const std::vector<Ice::Byte> _replyHdr;
Ice::Int _nextRequestId;
std::map<Ice::Int, Outgoing*> _requests;
std::map<Ice::Int, Outgoing*>::iterator _requestsHint;
struct AsyncRequest
{
OutgoingAsyncPtr p;
IceUtil::Time t;
};
std::map<Ice::Int, AsyncRequest> _asyncRequests;
std::map<Ice::Int, AsyncRequest>::iterator _asyncRequestsHint;
std::auto_ptr<Ice::LocalException> _exception;
BasicStream _batchStream;
bool _batchStreamInUse;
int _batchRequestNum;
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
|