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
|
// **********************************************************************
//
// 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.
//
// **********************************************************************
#include <Ice/LoggerUtil.h>
#include <Ice/Network.h>
#include <IceSSL/OpenSSLPluginI.h>
#include <IceSSL/SslAcceptor.h>
#include <IceSSL/SslTransceiver.h>
#include <IceSSL/TraceLevels.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
SOCKET
IceSSL::SslAcceptor::fd()
{
return _fd;
}
void
IceSSL::SslAcceptor::close()
{
if(_traceLevels->network >= 1)
{
Trace out(_logger, _traceLevels->networkCat);
out << "stopping to accept ssl connections at " << toString();
}
SOCKET fd = _fd;
_fd = INVALID_SOCKET;
closeSocket(fd);
}
void
IceSSL::SslAcceptor::listen()
{
try
{
doListen(_fd, _backlog);
}
catch(...)
{
_fd = INVALID_SOCKET;
throw;
}
if(_traceLevels->network >= 1)
{
Trace out(_logger, _traceLevels->networkCat);
out << "accepting ssl connections at " << toString();
}
}
TransceiverPtr
IceSSL::SslAcceptor::accept(int timeout)
{
SOCKET fd = doAccept(_fd, timeout);
setBlock(fd, false);
if(_traceLevels->network >= 1)
{
Trace out(_logger, _traceLevels->networkCat);
out << "accepted ssl connection\n" << fdToString(fd);
}
return _plugin->createTransceiver(IceSSL::Server, fd, timeout);
}
string
IceSSL::SslAcceptor::toString() const
{
return addrToString(_addr);
}
bool
IceSSL::SslAcceptor::equivalent(const string& host, int port) const
{
struct sockaddr_in addr;
getAddress(host, port, addr);
return compareAddress(addr, _addr);
}
int
IceSSL::SslAcceptor::effectivePort()
{
return ntohs(_addr.sin_port);
}
IceSSL::SslAcceptor::SslAcceptor(const OpenSSLPluginIPtr& plugin, const string& host, int port) :
_plugin(plugin),
_traceLevels(plugin->getTraceLevels()),
_logger(plugin->getLogger()),
_backlog(0)
{
if(_backlog <= 0)
{
_backlog = 5;
}
try
{
_fd = createSocket(false);
setBlock(_fd, false);
getAddress(host, port, _addr);
if(_traceLevels->network >= 2)
{
Trace out(_logger, _traceLevels->networkCat);
out << "attempting to bind to ssl socket\n" << toString();
}
doBind(_fd, _addr);
}
catch(...)
{
_fd = INVALID_SOCKET;
throw;
}
}
IceSSL::SslAcceptor::~SslAcceptor()
{
assert(_fd == INVALID_SOCKET);
}
|