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
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package IceSSL;
final class AcceptorI implements IceInternal.Acceptor
{
public java.nio.channels.ServerSocketChannel fd()
{
return _fd;
}
public void close()
{
if(_instance.traceLevel() >= 1)
{
String s = "stopping to accept " + _instance.protocol() + " connections at " + toString();
_instance.logger().trace(_instance.traceCategory(), s);
}
assert(_fd != null);
IceInternal.Network.closeSocketNoThrow(_fd);
_fd = null;
}
public void listen()
{
// Nothing to do.
if(_instance.traceLevel() >= 1)
{
StringBuffer s = new StringBuffer("listening for " + _instance.protocol() + " connections at ");
s.append(toString());
java.util.List<String> interfaces =
IceInternal.Network.getHostsForEndpointExpand(_addr.getAddress().getHostAddress(),
_instance.protocolSupport(), true);
if(!interfaces.isEmpty())
{
s.append("\nlocal interfaces: ");
s.append(IceUtilInternal.StringUtil.joinString(interfaces, ", "));
}
_instance.logger().trace(_instance.traceCategory(), s.toString());
}
}
public IceInternal.Transceiver accept()
{
//
// The plug-in may not be fully initialized.
//
if(!_instance.initialized())
{
Ice.PluginInitializationException ex = new Ice.PluginInitializationException();
ex.reason = "IceSSL: plug-in is not initialized";
throw ex;
}
java.nio.channels.SocketChannel fd = IceInternal.Network.doAccept(_fd);
javax.net.ssl.SSLEngine engine = null;
try
{
IceInternal.Network.setBlock(fd, false);
IceInternal.Network.setTcpBufSize(fd, _instance.properties(), _instance.logger());
java.net.InetSocketAddress peerAddr = (java.net.InetSocketAddress)fd.socket().getRemoteSocketAddress();
engine = _instance.createSSLEngine(true, peerAddr);
}
catch(RuntimeException ex)
{
IceInternal.Network.closeSocketNoThrow(fd);
throw ex;
}
if(_instance.traceLevel() >= 1)
{
_instance.logger().trace(_instance.traceCategory(), "accepting " + _instance.protocol() + " connection\n" +
IceInternal.Network.fdToString(fd));
}
return new TransceiverI(_instance, engine, fd, _adapterName);
}
public String protocol()
{
return _instance.protocol();
}
public String toString()
{
return IceInternal.Network.addrToString(_addr);
}
int effectivePort()
{
return _addr.getPort();
}
AcceptorI(Instance instance, String adapterName, String host, int port)
{
_instance = instance;
_adapterName = adapterName;
_backlog = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511);
try
{
_fd = IceInternal.Network.createTcpServerSocket();
IceInternal.Network.setBlock(_fd, false);
IceInternal.Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger());
if(!System.getProperty("os.name").startsWith("Windows"))
{
//
// Enable SO_REUSEADDR on Unix platforms to allow
// re-using the socket even if it's in the TIME_WAIT
// state. On Windows, this doesn't appear to be
// necessary and enabling SO_REUSEADDR would actually
// not be a good thing since it allows a second
// process to bind to an address even it's already
// bound by another process.
//
// TODO: using SO_EXCLUSIVEADDRUSE on Windows would
// probably be better but it's only supported by recent
// Windows versions (XP SP2, Windows Server 2003).
//
IceInternal.Network.setReuseAddress(_fd, true);
}
_addr = IceInternal.Network.getAddressForServer(host, port, _instance.protocolSupport(),
_instance.preferIPv6());
if(_instance.traceLevel() >= 2)
{
String s = "attempting to bind to " + _instance.protocol() + " socket " + toString();
_instance.logger().trace(_instance.traceCategory(), s);
}
_addr = IceInternal.Network.doBind(_fd, _addr, _backlog);
}
catch(RuntimeException ex)
{
_fd = null;
throw ex;
}
}
protected synchronized void finalize()
throws Throwable
{
try
{
IceUtilInternal.Assert.FinalizerAssert(_fd == null);
}
catch(java.lang.Exception ex)
{
}
finally
{
super.finalize();
}
}
private Instance _instance;
private String _adapterName;
private java.nio.channels.ServerSocketChannel _fd;
private int _backlog;
private java.net.InetSocketAddress _addr;
}
|