[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tigervnc-commits
Subject:    [Tigervnc-commits] SF.net SVN: tigervnc:[4846] trunk/java/com/tigervnc
From:       bphinz () users ! sourceforge ! net
Date:       2012-02-08 4:21:43
Message-ID: E1Ruz2N-0003V0-VC () sfp-svn-4 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 4846
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4846&view=rev
Author:   bphinz
Date:     2012-02-08 04:21:43 +0000 (Wed, 08 Feb 2012)
Log Message:
-----------
corrected return value for read function to match unix socket read. updated exception \
handling to match C code.

Modified Paths:
--------------
    trunk/java/com/tigervnc/network/FileDescriptor.java
    trunk/java/com/tigervnc/network/SocketDescriptor.java
    trunk/java/com/tigervnc/network/TcpSocket.java
    trunk/java/com/tigervnc/rdr/Exception.java
    trunk/java/com/tigervnc/rdr/FdInStream.java

Added Paths:
-----------
    trunk/java/com/tigervnc/network/SocketException.java
    trunk/java/com/tigervnc/rdr/SystemException.java

Modified: trunk/java/com/tigervnc/network/FileDescriptor.java
===================================================================
--- trunk/java/com/tigervnc/network/FileDescriptor.java	2012-02-05 21:49:03 UTC (rev \
                4845)
+++ trunk/java/com/tigervnc/network/FileDescriptor.java	2012-02-08 04:21:43 UTC (rev \
4846) @@ -18,14 +18,14 @@
  */
 package com.tigervnc.network;
 
-import java.lang.Exception;
 import java.io.IOException;
+import com.tigervnc.rdr.Exception;
 
 public interface FileDescriptor {
     
-  public int read(byte[] buf, int bufPtr, int length) throws java.lang.Exception;
-  public int write(byte[] buf, int bufPtr, int length) throws java.lang.Exception;
-  public int select(int interestOps, int timeout) throws java.lang.Exception;
+  public int read(byte[] buf, int bufPtr, int length) throws Exception;
+  public int write(byte[] buf, int bufPtr, int length) throws Exception;
+  public int select(int interestOps, int timeout) throws Exception;
   public void close() throws IOException;
 
 }

Modified: trunk/java/com/tigervnc/network/SocketDescriptor.java
===================================================================
--- trunk/java/com/tigervnc/network/SocketDescriptor.java	2012-02-05 21:49:03 UTC \
                (rev 4845)
+++ trunk/java/com/tigervnc/network/SocketDescriptor.java	2012-02-08 04:21:43 UTC \
(rev 4846) @@ -19,7 +19,6 @@
 package com.tigervnc.network;
 
 import java.io.IOException;
-import java.lang.Exception;
 
 import java.net.SocketAddress;
 import java.nio.*;
@@ -29,6 +28,8 @@
 import java.util.Set;
 import java.util.Iterator;
 
+import com.tigervnc.rdr.Exception;
+
 public class SocketDescriptor extends SocketChannel 
                               implements FileDescriptor {
 
@@ -38,7 +39,7 @@
       channel = SocketChannel.open();
       channel.configureBlocking(false);
       selector = Selector.open();
-    } catch (java.io.IOException e) {
+    } catch (IOException e) {
       throw new Exception(e.toString());
     }
     try {
@@ -54,11 +55,10 @@
     try {
       n = channel.read(b);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
       throw new Exception(e.toString());
     }
-    //if (n == 0)
-    //  throw new Exception;
+    if (n <= 0)
+      return (n == 0) ? -1 : 0;
     b.flip();
     b.get(buf, bufPtr, n);
     b.clear();
@@ -74,7 +74,6 @@
     try {
       n = channel.write(b);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
       throw new Exception(e.toString());
     }
     b.clear();
@@ -85,8 +84,7 @@
     int n;
     try {
       n = selector.select(timeout);
-    } catch (Exception e) {
-      System.out.println(e.toString());
+    } catch (java.io.IOException e) {
       throw new Exception(e.toString());
     }
     Set keys = selector.selectedKeys();
@@ -104,13 +102,12 @@
     return n;
   }
 
-  public int write(ByteBuffer buf) throws IOException {
+  public int write(ByteBuffer buf) throws Exception {
     int n = 0;
     try {
       n = channel.write(buf);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
-      throw e;
+      throw new Exception(e.toString());
     }
     return n;
   }
@@ -122,7 +119,7 @@
     try {
       n = channel.write(buf, offset, length);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
+      throw new Exception(e.toString());
     }
     return n;
   }
@@ -132,8 +129,7 @@
     try {
       n = channel.read(buf);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
-      throw e;
+      throw new Exception(e.toString());
     }
     return n;
   }
@@ -145,7 +141,7 @@
     try {
       n = channel.read(buf, offset, length);
     } catch (java.io.IOException e) {
-      System.out.println(e.toString());
+      throw new Exception(e.toString());
     }
     return n;
   }

Added: trunk/java/com/tigervnc/network/SocketException.java
===================================================================
--- trunk/java/com/tigervnc/network/SocketException.java	                        (rev \
                0)
+++ trunk/java/com/tigervnc/network/SocketException.java	2012-02-08 04:21:43 UTC (rev \
4846) @@ -0,0 +1,28 @@
+/* Copyright (C) 2012 TigerVNC Team
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+package com.tigervnc.network;
+
+import com.tigervnc.rdr.SystemException;
+
+public class SocketException extends SystemException {
+  public SocketException(String s) {
+    super(s);
+  }
+}
+

Modified: trunk/java/com/tigervnc/network/TcpSocket.java
===================================================================
--- trunk/java/com/tigervnc/network/TcpSocket.java	2012-02-05 21:49:03 UTC (rev 4845)
+++ trunk/java/com/tigervnc/network/TcpSocket.java	2012-02-08 04:21:43 UTC (rev 4846)
@@ -21,13 +21,13 @@
 
 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 TcpSocket(SocketDescriptor sock, boolean close) {
     super(new FdInStream(sock), new FdOutStream(sock), true);
-    //this.sock = sock;
     closeFd = close;
   }
 
@@ -71,30 +70,29 @@
 
     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 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;

Modified: trunk/java/com/tigervnc/rdr/Exception.java
===================================================================
--- trunk/java/com/tigervnc/rdr/Exception.java	2012-02-05 21:49:03 UTC (rev 4845)
+++ trunk/java/com/tigervnc/rdr/Exception.java	2012-02-08 04:21:43 UTC (rev 4846)
@@ -23,3 +23,15 @@
     super(s);
   }
 }
+
+class TimedOut extends Exception {
+  public TimedOut() {
+    super("Timed out");
+  }
+}
+
+class FrameException extends Exception {
+  public FrameException() {
+    super("Frame Exception");
+  }
+}

Modified: trunk/java/com/tigervnc/rdr/FdInStream.java
===================================================================
--- trunk/java/com/tigervnc/rdr/FdInStream.java	2012-02-05 21:49:03 UTC (rev 4845)
+++ trunk/java/com/tigervnc/rdr/FdInStream.java	2012-02-08 04:21:43 UTC (rev 4846)
@@ -153,24 +153,22 @@
 
       try {
         n = fd.select(SelectionKey.OP_READ, timeoutms);
-      } catch (java.lang.Exception e) {
-        System.out.println(e.toString());
-        throw new Exception(e.toString());
+      } catch (Exception e) {
+        throw new SystemException("select:"+e.toString());
       }
         
           
       if (n > 0) break;
       if (!wait) return 0;
-      //if (blockCallback == null) throw TimedOut();
+      if (blockCallback == null) throw new TimedOut();
     
       blockCallback.blockCallback();
     }
 
     try {
       n = fd.read(buf, bufPtr, len);
-    } catch (java.lang.Exception e) {
-      System.out.println("read:"+e.toString());
-      throw new Exception(e.toString());
+    } catch (Exception e) {
+      throw new SystemException("read:"+e.toString());
     }
 
     if (n == 0) throw new EndOfStream();

Added: trunk/java/com/tigervnc/rdr/SystemException.java
===================================================================
--- trunk/java/com/tigervnc/rdr/SystemException.java	                        (rev 0)
+++ trunk/java/com/tigervnc/rdr/SystemException.java	2012-02-08 04:21:43 UTC (rev \
4846) @@ -0,0 +1,26 @@
+/* Copyright (C) 2012 TigerVNC Team
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+package com.tigervnc.rdr;
+
+public class SystemException extends Exception {
+  public SystemException(String s) {
+    super(s);
+  }
+}
+

This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Tigervnc-commits mailing list
Tigervnc-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic