PlainSocketImpl.java [plain text]
package java.net;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
class PlainSocketImpl extends SocketImpl
{
static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
_Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
_Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
_Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
_Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
_Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
_Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
_Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
_Jv_IP_TOS_ = SocketOptions.IP_TOS,
_Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
_Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
_Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
_Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF,
_Jv_SO_KEEPALIVE_ = SocketOptions.SO_KEEPALIVE;
int fnum = -1;
int timeout = 0;
InetAddress localAddress;
public native void setOption(int optID, Object value) throws SocketException;
public native Object getOption(int optID) throws SocketException;
public native void shutdownInput () throws IOException;
public native void shutdownOutput () throws IOException;
protected native void create (boolean stream) throws IOException;
protected void connect (String host, int port) throws IOException
{
connect (new InetSocketAddress (InetAddress.getByName(host), port), 0);
}
protected void connect (InetAddress host, int port) throws IOException
{
connect (new InetSocketAddress (host, port), 0);
}
protected native void connect (SocketAddress addr, int timeout)
throws IOException;
protected native void bind (InetAddress host, int port) throws IOException;
protected native void listen (int backlog) throws IOException;
private native void accept (PlainSocketImpl s) throws IOException;
protected void accept (SocketImpl s) throws IOException
{
accept((PlainSocketImpl) s);
}
protected native int available() throws IOException;
protected native void close () throws IOException;
protected native void sendUrgentData(int data)
throws IOException;
private InputStream in;
private OutputStream out;
private native int read() throws IOException;
private native int read(byte[] buffer, int offset, int count)
throws IOException;
private native void write(int c) throws IOException;
private native void write(byte[] buffer, int offset, int count)
throws IOException;
protected void finalize() throws Throwable
{
synchronized (this)
{
if (fnum != -1)
try
{
close();
}
catch (IOException ex)
{
}
}
super.finalize();
}
protected InputStream getInputStream() throws IOException
{
if (in == null)
in = new SocketInputStream();
return in;
}
protected OutputStream getOutputStream() throws IOException
{
if (out == null)
out = new SocketOutputStream();
return out;
}
class SocketInputStream
extends InputStream
{
SocketInputStream()
{
}
public final void close() throws IOException
{
PlainSocketImpl.this.close();
}
public final int available() throws IOException
{
return PlainSocketImpl.this.available();
}
public final int read() throws IOException
{
return PlainSocketImpl.this.read();
}
public final int read(byte[] buffer, int offset, int length)
throws IOException
{
return PlainSocketImpl.this.read(buffer, offset, length);
}
public final int read(byte[] buffer)
throws IOException
{
return PlainSocketImpl.this.read(buffer, 0, buffer.length);
}
}
class SocketOutputStream
extends OutputStream
{
public final void close() throws IOException
{
PlainSocketImpl.this.close();
}
public final void write(int c) throws IOException
{
PlainSocketImpl.this.write(c);
}
public final void write(byte[] buffer, int offset, int length)
throws IOException
{
PlainSocketImpl.this.write(buffer, offset, length);
}
public final void write(byte[] buffer)
throws IOException
{
PlainSocketImpl.this.write(buffer, 0, buffer.length);
}
}
}