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
|
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/Logger.h>
#include <Ice/Buffer.h>
#include <Ice/Network.h>
#include <IceSSL/OpenSSL.h>
#include <IceSSL/SslConnection.h>
#include <IceSSL/SslTransceiver.h>
#include <IceSSL/PluginBaseI.h>
#include <IceSSL/TraceLevels.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
using IceSSL::ConnectionPtr;
SOCKET
IceSSL::SslTransceiver::fd()
{
return _fd;
}
void
IceSSL::SslTransceiver::close()
{
if(_traceLevels->network >= 1)
{
ostringstream s;
s << "closing ssl connection\n" << toString();
_logger->trace(_traceLevels->networkCat, s.str());
}
SOCKET fd = _fd;
_fd = INVALID_SOCKET;
int shutdown = 0;
int numRetries = 100;
int retries = -numRetries;
do
{
shutdown = _sslConnection->shutdown();
retries++;
}
while((shutdown == 0) && (retries < 0));
::shutdown(fd, SHUT_RDWR); // helps to unblock threads in recv()
closeSocket(fd);
}
void
IceSSL::SslTransceiver::shutdown()
{
if(_traceLevels->network >= 2)
{
ostringstream s;
s << "shutting down ssl connection\n" << toString();
_logger->trace(_traceLevels->networkCat, s.str());
}
int shutdown = 0;
int numRetries = 100;
int retries = -numRetries;
do
{
shutdown = _sslConnection->shutdown();
retries++;
}
while((shutdown == 0) && (retries < 0));
::shutdown(_fd, SHUT_WR); // Shutdown socket for writing
}
void
IceSSL::SslTransceiver::write(Buffer& buf, int timeout)
{
_sslConnection->write(buf, timeout);
}
void
IceSSL::SslTransceiver::read(Buffer& buf, int timeout)
{
if(!_sslConnection->read(buf, timeout))
{
if(_traceLevels->security >= IceSSL::SECURITY_WARNINGS)
{
_logger->trace(_traceLevels->securityCat, "WRN reading from ssl connection returns no bytes");
}
}
}
string
IceSSL::SslTransceiver::toString() const
{
return fdToString(_fd);
}
IceSSL::SslTransceiver::SslTransceiver(const PluginBaseIPtr& plugin,
SOCKET fd,
const ConnectionPtr& sslConnection) :
_traceLevels(plugin->getTraceLevels()),
_logger(plugin->getLogger()),
_fd(fd),
_sslConnection(sslConnection)
{
assert(sslConnection != 0);
FD_ZERO(&_rFdSet);
FD_ZERO(&_wFdSet);
}
IceSSL::SslTransceiver::~SslTransceiver()
{
assert(_fd == INVALID_SOCKET);
}
|