Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp
In directory usw-pr-cvs1:/tmp/cvs-serv17443/src/org/beepcore/beep/transport/tcp
Modified Files:
TCPSession.java
Log Message:
changed to make a single call to write
Index: TCPSession.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp/TCPSession.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** TCPSession.java 2001/11/23 04:24:04 1.17
--- TCPSession.java 2001/11/27 02:39:03 1.18
***************
*** 77,80 ****
--- 77,81 ----
// reusing fixed size buffers.
private byte headerBuffer[] = new byte[Frame.MAX_HEADER_SIZE];
+ private byte[] outputBuf = new byte[0];
private Object writerLock;
private Socket socket;
***************
*** 258,288 ****
try {
- // @todo consider the costs of colliding these into one
- // buffer and one write..test to see if it's faster
- // this way or faster copying.
OutputStream os = socket.getOutputStream();
- byte[] header = null;
synchronized (writerLock) {
! if (Log.isLogged(Log.SEV_DEBUG_VERBOSE)) {
! Log.logEntry(Log.SEV_DEBUG_VERBOSE, TCP_MAPPING,
! "Wrote the following\n");
}
! Iterator i = f.getBytes();
! while (i.hasNext()) {
! BufferSegment b = (BufferSegment) i.next();
! os.write(b.getData(), b.getOffset(), b.getLength());
! if (Log.isLogged(Log.SEV_DEBUG_VERBOSE)) {
! Log.logEntry(Log.SEV_DEBUG_VERBOSE, TCP_MAPPING,
! new String(b.getData(), b.getOffset(),
! b.getLength()));
! }
}
os.flush();
}
} catch (IOException e) {
--- 259,297 ----
try {
OutputStream os = socket.getOutputStream();
synchronized (writerLock) {
! /* Inspite of the extra data copy if is faster to have
! * a single call to write() (at least with the JVMs we
! * have tested with).
! */
! BufferSegment[] bs = f.getBytes();
!
! int n = 0;
! for (int i=0; i<bs.length; ++i) {
! n += bs[i].getLength();
}
! if (n > outputBuf.length) {
! outputBuf = new byte[n];
! }
! int off = 0;
! for (int i=0; i<bs.length; ++i) {
! System.arraycopy(bs[i].getData(), bs[i].getOffset(),
! outputBuf, off, bs[i].getLength());
! off += bs[i].getLength();
}
+ os.write(outputBuf, 0, n);
os.flush();
+
+ if (Log.isLogged(Log.SEV_DEBUG_VERBOSE)) {
+ Log.logEntry(Log.SEV_DEBUG_VERBOSE, TCP_MAPPING,
+ "Wrote the following\n" +
+ new String(outputBuf));
+ }
}
} catch (IOException e) {
|