From 8d37f2054b6da02957b12d02aaf96dd5eecc89c7 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Wed, 8 Feb 2012 04:21:43 +0000 Subject: corrected return value for read function to match unix socket read. updated exception handling to match C code. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4846 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/network/TcpSocket.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'java/com/tigervnc/network/TcpSocket.java') diff --git a/java/com/tigervnc/network/TcpSocket.java b/java/com/tigervnc/network/TcpSocket.java index 926aa975..9277dd14 100644 --- a/java/com/tigervnc/network/TcpSocket.java +++ b/java/com/tigervnc/network/TcpSocket.java @@ -21,13 +21,13 @@ package com.tigervnc.network; import com.tigervnc.rdr.FdInStream; import com.tigervnc.rdr.FdOutStream; +import com.tigervnc.rdr.Exception; import com.tigervnc.rfb.LogWriter; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.net.SocketException; import java.net.UnknownHostException; import java.nio.*; import java.nio.channels.*; @@ -46,7 +46,6 @@ public class TcpSocket extends Socket { public TcpSocket(SocketDescriptor sock, boolean close) { super(new FdInStream(sock), new FdOutStream(sock), true); - //this.sock = sock; closeFd = close; } @@ -71,30 +70,29 @@ public class TcpSocket extends Socket { try { sock = new SocketDescriptor(); - } catch(UnknownHostException e) { - throw new Exception("unable to create socket: "+e.toString()); + } catch(Exception e) { + throw new SocketException("unable to create socket: "+e.toString()); } /* Attempt to connect to the remote host */ try { result = sock.connect(new InetSocketAddress(addr, port)); } catch(java.io.IOException e) { - //throw new java.lang.Exception(e.getMessage()); - System.out.println("connect failed: "+e.getMessage()); + throw new SocketException("unable to connect:"+e.getMessage()); } if (!result && sock.isConnectionPending()) { while (!result) { try { result = sock.finishConnect(); - } catch(java.nio.channels.ClosedChannelException e) { + } catch(java.io.IOException e) { throw new Exception(e.getMessage()); } } } if (!result) - throw new Exception("unable connect to socket"); + throw new SocketException("unable connect to socket"); // Disable Nagle's algorithm, to reduce latency enableNagles(sock, false); @@ -154,8 +152,8 @@ public class TcpSocket extends Socket { public static boolean enableNagles(SocketChannel sock, boolean enable) { try { sock.socket().setTcpNoDelay(!enable); - } catch(SocketException e) { - vlog.error(e.getMessage()); + } catch(java.net.SocketException e) { + vlog.error("unable to setsockopt TCP_NODELAY: "+e.getMessage()); return false; } return true; -- cgit v1.2.3