author | michaelm |
Thu, 14 Nov 2019 10:16:28 +0000 | |
branch | unixdomainchannels |
changeset 59076 | 998df1368cca |
parent 59052 | 15e9a570c6e6 |
permissions | -rw-r--r-- |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
1 |
/* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
4 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
10 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
16 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
20 |
* |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
23 |
* questions. |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
24 |
*/ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
25 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
26 |
package sun.nio.ch; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
27 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
28 |
import java.io.FileDescriptor; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
29 |
import java.io.IOException; |
59076 | 30 |
import java.net.BindException; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
31 |
import java.net.ServerSocket; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
32 |
import java.net.SocketAddress; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
33 |
import java.net.SocketOption; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
34 |
import java.net.SocketTimeoutException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
35 |
import java.net.StandardProtocolFamily; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
36 |
import java.net.StandardSocketOptions; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
37 |
import java.nio.channels.AlreadyBoundException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
38 |
import java.nio.channels.AsynchronousCloseException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
39 |
import java.nio.channels.ClosedChannelException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
40 |
import java.nio.channels.IllegalBlockingModeException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
41 |
import java.nio.channels.NotYetBoundException; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
42 |
import java.nio.channels.SelectionKey; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
43 |
import java.nio.channels.ServerSocketChannel; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
44 |
import java.nio.channels.SocketChannel; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
45 |
import java.nio.channels.UnixDomainSocketAddress; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
46 |
import java.nio.channels.spi.SelectorProvider; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
47 |
import java.util.Collections; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
48 |
import java.util.HashSet; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
49 |
import java.util.Objects; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
50 |
import java.util.Set; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
51 |
import java.util.concurrent.locks.ReentrantLock; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
52 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
53 |
import sun.net.NetHooks; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
54 |
import sun.net.ext.ExtendedSocketOptions; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
55 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
56 |
/** |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
57 |
* An implementation of ServerSocketChannels |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
58 |
*/ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
59 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
60 |
public class UnixDomainServerSocketChannelImpl |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
61 |
extends ServerSocketChannelImpl |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
62 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
63 |
static { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
64 |
// register with InheritedChannel mechanism so it can create instances |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
65 |
// not yet sun.nio.ch.InheritedChannel.register(UnixDomainServerSocketChannelImpl::create); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
66 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
67 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
68 |
public UnixDomainServerSocketChannelImpl(SelectorProvider sp) throws IOException { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
69 |
super(sp, Net.unixDomainSocket()); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
70 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
71 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
72 |
public UnixDomainServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
73 |
throws IOException |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
74 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
75 |
super(sp, fd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
76 |
if (bound) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
77 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
78 |
localAddress = Net.localUnixAddress(fd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
79 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
80 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
81 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
82 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
83 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
84 |
public ServerSocket socket() { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
85 |
throw new UnsupportedOperationException("socket not supported"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
86 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
87 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
88 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
89 |
public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
90 |
throws IOException |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
91 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
92 |
Objects.requireNonNull(name); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
93 |
if (!supportedOptions().contains(name)) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
94 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
95 |
if (!name.type().isInstance(value)) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
96 |
throw new IllegalArgumentException("Invalid value '" + value + "'"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
97 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
98 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
99 |
ensureOpen(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
100 |
// no options that require special handling |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
101 |
Net.setSocketOption(fd, Net.UNSPEC, name, value); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
102 |
return this; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
103 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
104 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
105 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
106 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
107 |
@SuppressWarnings("unchecked") |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
108 |
public <T> T getOption(SocketOption<T> name) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
109 |
throws IOException |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
110 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
111 |
Objects.requireNonNull(name); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
112 |
if (!supportedOptions().contains(name)) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
113 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
114 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
115 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
116 |
ensureOpen(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
117 |
// no options that require special handling |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
118 |
return (T) Net.getSocketOption(fd, Net.UNSPEC, name); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
119 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
120 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
121 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
122 |
private static class DefaultOptionsHolder { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
123 |
static final Set<SocketOption<?>> defaultOptions = defaultOptions(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
124 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
125 |
private static Set<SocketOption<?>> defaultOptions() { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
126 |
HashSet<SocketOption<?>> set = new HashSet<>(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
127 |
set.add(StandardSocketOptions.SO_RCVBUF); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
128 |
return Collections.unmodifiableSet(set); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
129 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
130 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
131 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
132 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
133 |
public final Set<SocketOption<?>> supportedOptions() { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
134 |
return DefaultOptionsHolder.defaultOptions; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
135 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
136 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
137 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
138 |
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException { |
59076 | 139 |
if (local == null) |
140 |
throw new BindException("automatic bind not possible for Unix domain servers"); |
|
141 |
||
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
142 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
143 |
ensureOpen(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
144 |
if (localAddress != null) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
145 |
throw new AlreadyBoundException(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
146 |
UnixDomainSocketAddress usa = Net.checkUnixAddress(local); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
147 |
Net.unixDomainBind(fd, usa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
148 |
Net.listen(fd, backlog < 1 ? 50 : backlog); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
149 |
localAddress = Net.localUnixAddress(fd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
150 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
151 |
return this; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
152 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
153 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
154 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
155 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
156 |
int implAccept(FileDescriptor fd, FileDescriptor newfd, SocketAddress[] addrs) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
157 |
throws IOException |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
158 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
159 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
160 |
return Net.unixDomainAccept(this.fd, newfd, addrs); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
161 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
162 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
163 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
164 |
String getRevealedLocalAddressAsString(SocketAddress addr) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
165 |
// TODO |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
166 |
return addr.toString(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
167 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
168 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
169 |
@Override |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
170 |
SocketAddress getRevealedLocalAddress(SocketAddress addr) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
171 |
return addr; // TODO |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
172 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
173 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
174 |
SocketChannel finishAccept(FileDescriptor newfd, SocketAddress isa) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
175 |
throws IOException |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
176 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
177 |
try { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
178 |
// newly accepted socket is initially in blocking mode |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
179 |
IOUtil.configureBlocking(newfd, true); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
180 |
return new UnixDomainSocketChannelImpl(provider(), newfd, isa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
181 |
} catch (Exception e) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
182 |
nd.close(newfd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
183 |
throw e; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
184 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
185 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
186 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
187 |
/** |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
188 |
* Returns the local address, or null if not bound |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
189 |
*/ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
190 |
SocketAddress localAddress() { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
191 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
192 |
return localAddress; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
193 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
194 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
195 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
196 |
public String toString() { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
197 |
StringBuilder sb = new StringBuilder(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
198 |
sb.append(this.getClass().getName()); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
199 |
sb.append('['); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
200 |
if (!isOpen()) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
201 |
sb.append("closed"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
202 |
} else { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
203 |
synchronized (stateLock) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
204 |
UnixDomainSocketAddress addr = (UnixDomainSocketAddress)localAddress; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
205 |
if (addr == null) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
206 |
sb.append("unbound"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
207 |
} else { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
208 |
sb.append(getRevealedLocalAddressAsString(addr)); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
209 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
210 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
211 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
212 |
sb.append(']'); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
213 |
return sb.toString(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
214 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
diff
changeset
|
215 |
} |