Permalink
Browse files

Zero-copy channel-based version of StdInCLient

  • Loading branch information...
pzemtsov committed Jan 29, 2015
1 parent 1876799 commit 42e481ff3abbf923050dafe79dc305f6191a9e19
Showing with 8 additions and 5 deletions.
  1. +8 −5 StdInClient.java
View
@@ -14,8 +14,8 @@ public static void main (String [] args) throws Exception
FileChannel chan = new FileInputStream ("/proc/self/fd/0").getChannel ();
byte[] type = new byte [4];
- byte[] msg = new byte [1024];
buf.limit (0);
+ ByteBuffer msgBuf = buf.duplicate ();
while (true) {
long t0 = System.currentTimeMillis ();
@@ -27,8 +27,10 @@ public static void main (String [] args) throws Exception
ensure (4, chan);
int len = buf.getInt ();
ensure (len, chan);
- buf.get (msg, 0, len);
- processMessage (type, msg, len);
+ msgBuf.limit (buf.position () + len);
+ msgBuf.position (buf.position ());
+ buf.position (buf.position () + len);
+ processMessage (type, msgBuf);
sum += len + 8;
}
long t1 = System.currentTimeMillis ();
@@ -52,8 +54,9 @@ private static void ensure (int len, ByteChannel chan) throws IOException
}
}
- private static void processMessage (byte [] type, byte [] msg, int len)
+ static int num = 0;
+
+ private static void processMessage (byte [] type, ByteBuffer buf)
{
}
-
}

0 comments on commit 42e481f

Please sign in to comment.