/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// Make a socket channel look like a socket.
//
// The only aspects of java.net.Socket-hood that we don't attempt to emulate
// here are the interrupted-I/O exceptions (which our Solaris implementations
// attempt to support) and the sending of urgent data. Otherwise an adapted
// socket should look enough like a real java.net.Socket to fool most of the
// developers most of the time, right down to the exception message strings.
//
// The methods in this class are defined in exactly the same order as in
// java.net.Socket so as to simplify tracking future changes to that class.
//
public class SocketAdaptor
extends Socket
{
// The channel being adapted
// Timeout "option" value for reads
super((SocketImpl) null);
}
try {
return new SocketAdaptor(sc);
} catch (SocketException e) {
throw new InternalError("Should not reach here");
}
}
return sc;
}
// Override this method just to protect against changes in the superclass
//
}
throw new IllegalArgumentException("connect: The address can't be null");
if (timeout < 0)
throw new IllegalArgumentException("connect: timeout can't be negative");
synchronized (sc.blockingLock()) {
if (!sc.isBlocking())
throw new IllegalBlockingModeException();
try {
if (timeout == 0) {
return;
}
// Implement timeout with a selector
sc.configureBlocking(false);
try {
return;
for (;;) {
throw new ClosedChannelException();
if (ns > 0 &&
break;
if (to <= 0) {
try {
} catch (IOException x) { }
throw new SocketTimeoutException();
}
}
} finally {
sc.configureBlocking(true);
}
} catch (Exception x) {
Net.translateException(x, true);
}
}
}
try {
} catch (Exception x) {
}
}
return null;
} else {
}
}
}
}
public int getPort() {
return 0;
} else {
}
}
public int getLocalPort() {
return -1;
} else {
}
}
private class SocketInputStream
extends ChannelInputStream
{
private SocketInputStream() {
super(sc);
}
throws IOException
{
synchronized (sc.blockingLock()) {
if (!sc.isBlocking())
throw new IllegalBlockingModeException();
if (timeout == 0)
// Implement timeout with a selector
sc.configureBlocking(false);
int n = 0;
try {
return n;
for (;;) {
throw new ClosedChannelException();
return n;
}
if (to <= 0)
throw new SocketTimeoutException();
}
} finally {
sc.configureBlocking(true);
}
}
}
}
throw new SocketException("Socket is closed");
if (!sc.isConnected())
throw new SocketException("Socket is not connected");
if (!sc.isInputOpen())
throw new SocketException("Socket input is shutdown");
if (socketInputStream == null) {
try {
new PrivilegedExceptionAction<InputStream>() {
return new SocketInputStream();
}
});
throw (IOException)e.getException();
}
}
return socketInputStream;
}
throw new SocketException("Socket is closed");
if (!sc.isConnected())
throw new SocketException("Socket is not connected");
if (!sc.isOutputOpen())
throw new SocketException("Socket output is shutdown");
try {
new PrivilegedExceptionAction<OutputStream>() {
}
});
throw (IOException)e.getException();
}
return os;
}
throws SocketException
{
try {
} catch (IOException x) {
}
}
throws SocketException
{
try {
} catch (IOException x) {
}
}
try {
} catch (IOException x) {
return false; // keep compiler happy
}
}
try {
} catch (IOException x) {
return -1; // keep compiler happy
}
}
}
}
if (!on)
linger = -1;
}
}
synchronized (sc.blockingLock()) {
if (!sc.isBlocking())
throw new IllegalBlockingModeException();
assert n == 1;
}
}
}
}
if (timeout < 0)
throw new IllegalArgumentException("timeout can't be negative");
}
return timeout;
}
// size 0 valid for SocketChannel, invalid for Socket
if (size <= 0)
throw new IllegalArgumentException("Invalid send size");
}
}
// size 0 valid for SocketChannel, invalid for Socket
if (size <= 0)
throw new IllegalArgumentException("Invalid receive size");
}
}
}
}
}
}
}
}
}
try {
sc.shutdownInput();
} catch (Exception x) {
}
}
try {
sc.shutdownOutput();
} catch (Exception x) {
}
}
if (sc.isConnected())
return "Socket[addr=" + getInetAddress() +
",port=" + getPort() +
return "Socket[unconnected]";
}
public boolean isConnected() {
return sc.isConnected();
}
public boolean isBound() {
}
public boolean isClosed() {
}
public boolean isInputShutdown() {
return !sc.isInputOpen();
}
public boolean isOutputShutdown() {
return !sc.isOutputOpen();
}
}