home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / net / PlainSocketImpl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  3.0 KB  |  127 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7.  
  8. class PlainSocketImpl extends SocketImpl {
  9.    protected synchronized void create(boolean stream) throws IOException {
  10.       super.fd = new FileDescriptor();
  11.       this.socketCreate(stream);
  12.    }
  13.  
  14.    protected void connect(String host, int port) throws UnknownHostException, IOException {
  15.       IOException pending = null;
  16.  
  17.       try {
  18.          InetAddress address = InetAddress.getByName(host);
  19.          int i = 0;
  20.  
  21.          while(i < 3) {
  22.             try {
  23.                this.socketConnect(address, port);
  24.                return;
  25.             } catch (ProtocolException e) {
  26.                this.socketClose();
  27.                super.fd = new FileDescriptor();
  28.                this.socketCreate(true);
  29.                pending = e;
  30.                ++i;
  31.             } catch (IOException e) {
  32.                this.socketClose();
  33.                throw e;
  34.             }
  35.          }
  36.       } catch (UnknownHostException e) {
  37.          pending = e;
  38.       }
  39.  
  40.       this.socketClose();
  41.       throw pending;
  42.    }
  43.  
  44.    protected void connect(InetAddress address, int port) throws IOException {
  45.       super.port = port;
  46.       super.address = address;
  47.       ProtocolException pending = null;
  48.       int i = 0;
  49.  
  50.       while(i < 3) {
  51.          try {
  52.             this.socketConnect(address, port);
  53.             return;
  54.          } catch (ProtocolException e) {
  55.             this.socketClose();
  56.             super.fd = new FileDescriptor();
  57.             this.socketCreate(true);
  58.             pending = e;
  59.             ++i;
  60.          } catch (IOException e) {
  61.             this.socketClose();
  62.             throw e;
  63.          }
  64.       }
  65.  
  66.       this.socketClose();
  67.       throw pending;
  68.    }
  69.  
  70.    protected synchronized void bind(InetAddress address, int lport) throws IOException {
  71.       this.socketBind(address, lport);
  72.    }
  73.  
  74.    protected synchronized void listen(int count) throws IOException {
  75.       this.socketListen(count);
  76.    }
  77.  
  78.    protected synchronized void accept(SocketImpl s) throws IOException {
  79.       this.socketAccept(s);
  80.    }
  81.  
  82.    protected synchronized InputStream getInputStream() throws IOException {
  83.       return new SocketInputStream(this);
  84.    }
  85.  
  86.    protected synchronized OutputStream getOutputStream() throws IOException {
  87.       return new SocketOutputStream(this);
  88.    }
  89.  
  90.    protected synchronized int available() throws IOException {
  91.       return this.socketAvailable();
  92.    }
  93.  
  94.    protected synchronized void close() throws IOException {
  95.       if (super.fd != null) {
  96.          this.socketClose();
  97.       }
  98.  
  99.    }
  100.  
  101.    protected synchronized void finalize() throws IOException {
  102.       if (super.fd != null) {
  103.          this.socketClose();
  104.       }
  105.  
  106.    }
  107.  
  108.    private native void socketCreate(boolean var1) throws IOException;
  109.  
  110.    private native void socketConnect(InetAddress var1, int var2) throws IOException;
  111.  
  112.    private native void socketBind(InetAddress var1, int var2) throws IOException;
  113.  
  114.    private native void socketListen(int var1) throws IOException;
  115.  
  116.    private native void socketAccept(SocketImpl var1) throws IOException;
  117.  
  118.    private native int socketAvailable() throws IOException;
  119.  
  120.    private native void socketClose() throws IOException;
  121.  
  122.    static {
  123.       SecurityManager.setScopePermission();
  124.       System.loadLibrary("net");
  125.    }
  126. }
  127.