home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.FileDescriptor;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
-
- class PlainSocketImpl extends SocketImpl {
- protected synchronized void create(boolean stream) throws IOException {
- super.fd = new FileDescriptor();
- this.socketCreate(stream);
- }
-
- protected void connect(String host, int port) throws UnknownHostException, IOException {
- IOException pending = null;
-
- try {
- InetAddress address = InetAddress.getByName(host);
- int i = 0;
-
- while(i < 3) {
- try {
- this.socketConnect(address, port);
- return;
- } catch (ProtocolException e) {
- this.socketClose();
- super.fd = new FileDescriptor();
- this.socketCreate(true);
- pending = e;
- ++i;
- } catch (IOException e) {
- this.socketClose();
- throw e;
- }
- }
- } catch (UnknownHostException e) {
- pending = e;
- }
-
- this.socketClose();
- throw pending;
- }
-
- protected void connect(InetAddress address, int port) throws IOException {
- super.port = port;
- super.address = address;
- ProtocolException pending = null;
- int i = 0;
-
- while(i < 3) {
- try {
- this.socketConnect(address, port);
- return;
- } catch (ProtocolException e) {
- this.socketClose();
- super.fd = new FileDescriptor();
- this.socketCreate(true);
- pending = e;
- ++i;
- } catch (IOException e) {
- this.socketClose();
- throw e;
- }
- }
-
- this.socketClose();
- throw pending;
- }
-
- protected synchronized void bind(InetAddress address, int lport) throws IOException {
- this.socketBind(address, lport);
- }
-
- protected synchronized void listen(int count) throws IOException {
- this.socketListen(count);
- }
-
- protected synchronized void accept(SocketImpl s) throws IOException {
- this.socketAccept(s);
- }
-
- protected synchronized InputStream getInputStream() throws IOException {
- return new SocketInputStream(this);
- }
-
- protected synchronized OutputStream getOutputStream() throws IOException {
- return new SocketOutputStream(this);
- }
-
- protected synchronized int available() throws IOException {
- return this.socketAvailable();
- }
-
- protected synchronized void close() throws IOException {
- if (super.fd != null) {
- this.socketClose();
- }
-
- }
-
- protected synchronized void finalize() throws IOException {
- if (super.fd != null) {
- this.socketClose();
- }
-
- }
-
- private native void socketCreate(boolean var1) throws IOException;
-
- private native void socketConnect(InetAddress var1, int var2) throws IOException;
-
- private native void socketBind(InetAddress var1, int var2) throws IOException;
-
- private native void socketListen(int var1) throws IOException;
-
- private native void socketAccept(SocketImpl var1) throws IOException;
-
- private native int socketAvailable() throws IOException;
-
- private native void socketClose() throws IOException;
-
- static {
- SecurityManager.setScopePermission();
- System.loadLibrary("net");
- }
- }
-