| Method from sun.nio.ch.SocketAdaptor Detail: |
public void bind(SocketAddress local) throws IOException {
try {
if (local == null)
local = new InetSocketAddress(0);
sc.bind(local);
} catch (Exception x) {
Net.translateException(x);
}
}
|
public void close() throws IOException {
try {
sc.close();
} catch (Exception x) {
Net.translateToSocketException(x);
}
}
|
public void connect(SocketAddress remote) throws IOException {
connect(remote, 0);
}
|
public void connect(SocketAddress remote,
int timeout) throws IOException {
if (remote == null)
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) {
sc.connect(remote);
return;
}
// Implement timeout with a selector
SelectionKey sk = null;
Selector sel = null;
sc.configureBlocking(false);
try {
if (sc.connect(remote))
return;
sel = Util.getTemporarySelector(sc);
sk = sc.register(sel, SelectionKey.OP_CONNECT);
long to = timeout;
for (;;) {
if (!sc.isOpen())
throw new ClosedChannelException();
long st = System.currentTimeMillis();
int ns = sel.select(to);
if (ns > 0 &&
sk.isConnectable() && sc.finishConnect())
break;
sel.selectedKeys().remove(sk);
to -= System.currentTimeMillis() - st;
if (to < = 0) {
try {
sc.close();
} catch (IOException x) { }
throw new SocketTimeoutException();
}
}
} finally {
if (sk != null)
sk.cancel();
if (sc.isOpen())
sc.configureBlocking(true);
if (sel != null)
Util.releaseTemporarySelector(sel);
}
} catch (Exception x) {
Net.translateException(x, true);
}
}
}
|
public static Socket create(SocketChannelImpl sc) {
return new SocketAdaptor(sc);
}
|
public SocketChannel getChannel() {
return sc;
}
|
public InetAddress getInetAddress() {
if (!sc.isConnected())
return null;
return Net.asInetSocketAddress(sc.remoteAddress()).getAddress();
}
|
public InputStream getInputStream() throws IOException {
if (!sc.isOpen())
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 {
socketInputStream = AccessController.doPrivileged(
new PrivilegedExceptionAction< InputStream >() {
public InputStream run() throws IOException {
return new SocketInputStream();
}
});
} catch (java.security.PrivilegedActionException e) {
throw (IOException)e.getException();
}
}
return socketInputStream;
}
|
public boolean getKeepAlive() throws SocketException {
return opts().getKeepAlive();
}
|
public InetAddress getLocalAddress() {
if (!sc.isBound())
return new InetSocketAddress(0).getAddress();
return Net.asInetSocketAddress(sc.localAddress()).getAddress();
}
|
public int getLocalPort() {
if (!sc.isBound())
return -1;
return Net.asInetSocketAddress(sc.localAddress()).getPort();
}
|
public boolean getOOBInline() throws SocketException {
return opts().getOOBInline();
}
|
public OutputStream getOutputStream() throws IOException {
if (!sc.isOpen())
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");
OutputStream os = null;
try {
os = AccessController.doPrivileged(
new PrivilegedExceptionAction< OutputStream >() {
public OutputStream run() throws IOException {
return Channels.newOutputStream(sc);
}
});
} catch (java.security.PrivilegedActionException e) {
throw (IOException)e.getException();
}
return os;
}
|
public int getPort() {
if (!sc.isConnected())
return 0;
return Net.asInetSocketAddress(sc.remoteAddress()).getPort();
}
|
public int getReceiveBufferSize() throws SocketException {
return opts().getReceiveBufferSize();
}
|
public boolean getReuseAddress() throws SocketException {
return opts().getReuseAddress();
}
|
public int getSendBufferSize() throws SocketException {
return opts().getSendBufferSize();
}
|
public int getSoLinger() throws SocketException {
return opts().getSoLinger();
}
|
public int getSoTimeout() throws SocketException {
return timeout;
}
|
public boolean getTcpNoDelay() throws SocketException {
return opts().getTcpNoDelay();
}
|
public int getTrafficClass() throws SocketException {
int tc = opts().getTrafficClass();
if (tc < 0) {
tc = trafficClass;
}
return tc;
}
|
public boolean isBound() {
return sc.isBound();
}
|
public boolean isClosed() {
return !sc.isOpen();
}
|
public boolean isConnected() {
return sc.isConnected();
}
|
public boolean isInputShutdown() {
return !sc.isInputOpen();
}
|
public boolean isOutputShutdown() {
return !sc.isOutputOpen();
}
|
public void sendUrgentData(int data) throws IOException {
throw new SocketException("Urgent data not supported");
}
|
public void setKeepAlive(boolean on) throws SocketException {
opts().setKeepAlive(on);
}
|
public void setOOBInline(boolean on) throws SocketException {
opts().setOOBInline(on);
}
|
public void setReceiveBufferSize(int size) throws SocketException {
opts().setReceiveBufferSize(size);
}
|
public void setReuseAddress(boolean on) throws SocketException {
opts().setReuseAddress(on);
}
|
public void setSendBufferSize(int size) throws SocketException {
opts().setSendBufferSize(size);
}
|
public void setSoLinger(boolean on,
int linger) throws SocketException {
opts().setSoLinger(on, linger);
}
|
public void setSoTimeout(int timeout) throws SocketException {
if (timeout < 0)
throw new IllegalArgumentException("timeout can't be negative");
this.timeout = timeout;
}
|
public void setTcpNoDelay(boolean on) throws SocketException {
opts().setTcpNoDelay(on);
}
|
public void setTrafficClass(int tc) throws SocketException {
opts().setTrafficClass(tc);
trafficClass = tc;
}
|
public void shutdownInput() throws IOException {
try {
sc.shutdownInput();
} catch (Exception x) {
Net.translateException(x);
}
}
|
public void shutdownOutput() throws IOException {
try {
sc.shutdownOutput();
} catch (Exception x) {
Net.translateException(x);
}
}
|
public String toString() {
if (sc.isConnected())
return "Socket[addr=" + getInetAddress() +
",port=" + getPort() +
",localport=" + getLocalPort() + "]";
return "Socket[unconnected]";
}
|