Michael Caron avatar Michael Caron committed 8ed27c6

Increased buffer to 1k (granted, larger than necessary, but it's still going to work).
Clears input buffer before each write to make sure there's nothing unexpected on the wire.

Comments (0)

Files changed (2)

src/main/java/com/intelix/net/Connection.java

 
 public abstract class Connection {
 
-    static final int MAX_BUFFER_SIZE = 70;
+    static final int MAX_BUFFER_SIZE = 1024 /* increased from 70 */;
     private byte[] bufferIn;
     private byte[] bufferOut;
     private int buffLimit = 0;
             }
             Logger.getLogger(getClass().getName()).log(Level.FINE, ">>>>WRITE: [{0}]", sBuff);
 
+            clearInput(500);
             getOutStream().write(bufferOut);
             getOutStream().flush();
 
     }
 
     public void write(List<Command> commands) throws IOException {
+        /* maybe try writing all the commands at once to improve perf. */
         for (Command c : commands) {
             write(c);
         }
             {
                 int avl = in.available();
                 Logger.getLogger(getClass().getName()).log(Level.FINE,"Clearing input buffer. Bytes available: {0}.",avl);
-                in.skip(in.available());
+                long skipped = in.skip(avl);
+                Logger.getLogger(getClass().getName()).log(Level.FINE, "Skipped {0} bytes", skipped);
                 try {
                     Logger.getLogger(getClass().getName()).log(Level.FINE,"Waiting {0} before another clearing.",waitTimeInMillisec);
                     Thread.sleep(waitTimeInMillisec);

src/main/java/com/intelix/net/IPConnection.java

         if (!this.connected) {
             return;
         }
-        this.outStream = new BufferedOutputStream(this.sock.getOutputStream());
-        this.inStream = new BufferedInputStream(this.sock.getInputStream());
+        this.outStream = new BufferedOutputStream(this.sock.getOutputStream(), MAX_BUFFER_SIZE);
+        this.inStream = new BufferedInputStream(this.sock.getInputStream(), MAX_BUFFER_SIZE);
     }
 
     @Override
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.