summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/SslConnectionOpenSSL.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/SslConnectionOpenSSL.h')
-rw-r--r--cpp/src/Ice/SslConnectionOpenSSL.h90
1 files changed, 85 insertions, 5 deletions
diff --git a/cpp/src/Ice/SslConnectionOpenSSL.h b/cpp/src/Ice/SslConnectionOpenSSL.h
index 9a89277262f..716da8cd2c3 100644
--- a/cpp/src/Ice/SslConnectionOpenSSL.h
+++ b/cpp/src/Ice/SslConnectionOpenSSL.h
@@ -29,6 +29,85 @@ namespace OpenSSL
using namespace Ice;
+class SafeFlag
+{
+public:
+ SafeFlag(bool flagVal = false)
+ {
+ _flag = flagVal;
+ }
+
+ ~SafeFlag()
+ {
+ }
+
+ bool checkAndSet()
+ {
+ JTCSyncT<JTCMutex> sync(_mutex);
+
+ if (_flag)
+ {
+ return false;
+ }
+ else
+ {
+ _flag = true;
+ return true;
+ }
+ }
+
+ bool check()
+ {
+ JTCSyncT<JTCMutex> sync(_mutex);
+ return _flag;
+ }
+
+ void set()
+ {
+ JTCSyncT<JTCMutex> sync(_mutex);
+ _flag = true;
+ }
+
+ void unset()
+ {
+ JTCSyncT<JTCMutex> sync(_mutex);
+ _flag = false;
+ }
+
+private:
+ JTCMutex _mutex;
+ bool _flag;
+};
+
+
+class HandshakeSentinel
+{
+
+public:
+ HandshakeSentinel(SafeFlag& handshakeFlag) :
+ _flag(handshakeFlag)
+ {
+ _ownHandshake = _flag.checkAndSet();
+ }
+
+ ~HandshakeSentinel()
+ {
+ if (_ownHandshake)
+ {
+ _flag.unset();
+ }
+ }
+
+ bool ownHandshake()
+ {
+ return _ownHandshake;
+ }
+
+private:
+ bool _ownHandshake;
+ SafeFlag& _flag;
+};
+
class Connection : public IceSecurity::Ssl::Connection
{
@@ -47,13 +126,14 @@ public:
void setTrace(TraceLevelsPtr traceLevels) { _traceLevels = traceLevels; };
void setLogger(LoggerPtr traceLevels) { _logger = traceLevels; };
- void setHandshakeReadTimeout(int timeout) { _handshakeReadTimeout = timeout; };
+ void setHandshakeReadTimeout(int timeout) { _handshakeReadTimeout = timeout; };
protected:
int connect();
int accept();
int renegotiate();
+ int initialize(int timeout);
inline int pending() { return SSL_pending(_sslConnection); };
inline int getLastError() const { return SSL_get_error(_sslConnection, _lastError); };
@@ -103,12 +183,12 @@ protected:
System* _system;
- JTCMutex _initMutex;
+ SafeFlag _handshakeFlag;
int _initWantRead;
int _initWantWrite;
- bool _timeoutEncountered;
- int _handshakeReadTimeout;
- int _readTimeout;
+ bool _timeoutEncountered;
+ int _handshakeReadTimeout;
+ int _readTimeout;
};
}