home *** CD-ROM | disk | FTP | other *** search
- package sun.rmi.transport.tcp;
-
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.ConnectException;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.rmi.ConnectIOException;
- import java.rmi.RemoteException;
- import java.rmi.server.LogStream;
- import java.rmi.server.RMISocketFactory;
- import sun.rmi.transport.Channel;
- import sun.rmi.transport.Connection;
- import sun.rmi.transport.proxy.RMISocketInfo;
-
- public class TCPConnection implements Connection {
- private Socket socket;
- private Channel channel;
- // $FF: renamed from: in java.io.InputStream
- private InputStream field_0;
- private OutputStream out;
- private long expiration = Long.MAX_VALUE;
-
- public TCPConnection(TCPChannel var1, InputStream var2, OutputStream var3) {
- this.socket = null;
- this.channel = var1;
- this.field_0 = var2;
- this.out = var3;
- }
-
- public TCPConnection(Channel var1, TCPEndpoint var2) throws RemoteException {
- this.channel = var1;
- RMISocketFactory var3 = RMISocketFactory.getSocketFactory();
- if (var3 == null) {
- var3 = TCPTransport.defaultSocketFactory;
- }
-
- try {
- this.socket = var3.createSocket(var2.getHost(), var2.getPort());
- } catch (UnknownHostException var6) {
- throw new java.rmi.UnknownHostException("Unknown host: " + var2, var6);
- } catch (ConnectException var7) {
- throw new java.rmi.ConnectException("Connection refused to host: " + var2, var7);
- } catch (IOException var8) {
- throw new ConnectIOException("Error creating connection to: " + var2, var8);
- }
-
- try {
- this.socket.setTcpNoDelay(true);
- } catch (Exception var5) {
- }
- }
-
- public TCPConnection(TCPChannel var1, Socket var2) {
- this.socket = var2;
- this.channel = var1;
- }
-
- public OutputStream getOutputStream() throws IOException {
- if (this.out == null) {
- this.out = new BufferedOutputStream(this.socket.getOutputStream());
- }
-
- return this.out;
- }
-
- public void releaseOutputStream() throws IOException {
- if (this.out != null) {
- this.out.flush();
- }
-
- }
-
- public InputStream getInputStream() throws IOException {
- if (this.field_0 == null) {
- this.field_0 = new BufferedInputStream(this.socket.getInputStream());
- }
-
- return this.field_0;
- }
-
- public void releaseInputStream() {
- }
-
- public boolean isReusable() {
- return this.socket != null && this.socket instanceof RMISocketInfo ? ((RMISocketInfo)this.socket).isReusable() : true;
- }
-
- void setExpiration(long var1) {
- this.expiration = var1;
- }
-
- boolean expired(long var1) {
- return this.expiration <= var1;
- }
-
- public void close() throws IOException {
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPConnection.close: close connection");
- }
-
- if (this.socket != null) {
- this.socket.close();
- } else {
- this.field_0.close();
- this.out.close();
- }
- }
-
- public Channel getChannel() {
- return this.channel;
- }
- }
-