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
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
// Note: This pragma is used to disable spurious warning messages having
// to do with the length of debug symbols exceeding 255 characters.
// This is due to STL template identifiers expansion.
// The MSDN Library recommends that you put this pragma directive
// in place to avoid the warnings.
#ifdef WIN32
# pragma warning(disable:4786)
#endif
#include <Ice/SystemInternal.h>
#include <Ice/SslAcceptor.h>
#include <Ice/SslTransceiver.h>
#include <Ice/Instance.h>
#include <Ice/TraceLevels.h>
#include <Ice/Logger.h>
#include <Ice/Network.h>
#include <Ice/Properties.h>
#include <Ice/Exception.h>
#include <Ice/SslException.h>
#include <sstream>
using namespace std;
using namespace Ice;
using namespace IceInternal;
using std::string;
using std::ostringstream;
using IceSSL::Connection;
using IceSSL::SystemInternalPtr;
SOCKET
IceInternal::SslAcceptor::fd()
{
return _fd;
}
void
IceInternal::SslAcceptor::close()
{
if (_traceLevels->network >= 1)
{
ostringstream s;
s << "stopping to accept ssl connections at " << toString();
_logger->trace(_traceLevels->networkCat, s.str());
}
SOCKET fd = _fd;
_fd = INVALID_SOCKET;
closeSocket(fd);
}
void
IceInternal::SslAcceptor::listen()
{
try
{
doListen(_fd, _backlog);
}
catch(...)
{
_fd = INVALID_SOCKET;
throw;
}
if (_traceLevels->network >= 1)
{
ostringstream s;
s << "accepting ssl connections at " << toString();
_logger->trace(_traceLevels->networkCat, s.str());
}
}
TransceiverPtr
IceInternal::SslAcceptor::accept(int timeout)
{
SOCKET fd = doAccept(_fd, timeout);
if (_traceLevels->network >= 1)
{
ostringstream s;
s << "accepted ssl connection\n" << fdToString(fd);
_logger->trace(_traceLevels->networkCat, s.str());
}
// Get an instance of the SslSystem.
SystemInternalPtr sslSystem = _instance->getSslSystem();
assert(sslSystem != 0);
IceSSL::ConnectionPtr connection = sslSystem->createConnection(IceSSL::Server, fd);
TransceiverPtr transPtr = new SslTransceiver(_instance, fd, connection);
return transPtr;
}
string
IceInternal::SslAcceptor::toString() const
{
return addrToString(_addr);
}
bool
IceInternal::SslAcceptor::equivalent(const string& host, int port) const
{
struct sockaddr_in addr;
getAddress(host, port, addr);
return memcmp(&addr, &_addr, sizeof(struct sockaddr_in)) == 0;
}
int
IceInternal::SslAcceptor::effectivePort()
{
return ntohs(_addr.sin_port);
}
IceInternal::SslAcceptor::SslAcceptor(const InstancePtr& instance, const string& host, int port) :
_instance(instance),
_traceLevels(instance->traceLevels()),
_logger(instance->logger()),
_backlog(0)
{
if (_backlog <= 0)
{
_backlog = 5;
}
try
{
_fd = createSocket(false);
getAddress(host, port, _addr);
doBind(_fd, _addr);
}
catch(...)
{
_fd = INVALID_SOCKET;
throw;
}
}
IceInternal::SslAcceptor::~SslAcceptor()
{
assert(_fd == INVALID_SOCKET);
}
|