[Beepcore-java-commits] CVS: beepcore-java/src/org/beepcore/beep/transport/tcp TCPSession.java,1.19,
Status: Beta
Brought to you by:
huston
From: Huston F. <hu...@us...> - 2001-11-27 16:05:02
|
Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp In directory usw-pr-cvs1:/tmp/cvs-serv14355/src/org/beepcore/beep/transport/tcp Modified Files: TCPSession.java Log Message: Improved header parsing Index: TCPSession.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp/TCPSession.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** TCPSession.java 2001/11/27 07:31:21 1.19 --- TCPSession.java 2001/11/27 16:04:59 1.20 *************** *** 39,42 **** --- 39,43 ---- import org.beepcore.beep.core.SessionTuningProperties; import org.beepcore.beep.util.BufferSegment; + import org.beepcore.beep.util.HeaderParser; import org.beepcore.beep.util.Log; *************** *** 54,67 **** // Constants ! private static final String ERR_SEND_FRAME_FAILED = ! "Unable to send a frame"; ! private static final String ERR_TCP_BUFFER_TOO_LARGE = ""; ! private static final String SEQ_PREFIX = "SEQ "; ! private static final char NEWLINE_CHAR = '\n'; ! private static final int DEFAULT_PROPERTIES_SIZE = 4; ! private static final int DEFAULT_RECEIVE_BUFFER_SIZE = 4 * 1024; private static final int MAX_RECEIVE_BUFFER_SIZE = 64 * 1024; - private static final int MIN_RECEIVE_BUFFER_SIZE = 4 * 1024; - private static final int SEQ_LENGTH = SEQ_PREFIX.length(); private static final String TCP_MAPPING = "TCP Mapping"; private static final String CRLF = "\r\n"; --- 55,60 ---- // Constants ! private static final char[] MESSAGE_TYPE_SEQ = new char[] {'S', 'E', 'Q'}; private static final int MAX_RECEIVE_BUFFER_SIZE = 64 * 1024; private static final String TCP_MAPPING = "TCP Mapping"; private static final String CRLF = "\r\n"; *************** *** 80,87 **** // Instance Data - // @todo had these per stack, but have - // since changed my tune, since we'll be thread/session - // for probably a while yet...this'll help on performance. - // reusing fixed size buffers. private byte headerBuffer[] = new byte[Frame.MAX_HEADER_SIZE]; private byte[] outputBuf = new byte[0]; --- 73,76 ---- *************** *** 397,401 **** StringBuffer sb = new StringBuffer(Frame.MAX_HEADER_SIZE); ! sb.append(SEQ_PREFIX); sb.append(this.getChannelNumberAsString(channel)); sb.append(' '); --- 386,391 ---- StringBuffer sb = new StringBuffer(Frame.MAX_HEADER_SIZE); ! sb.append(MESSAGE_TYPE_SEQ); ! sb.append(' '); sb.append(this.getChannelNumberAsString(channel)); sb.append(' '); *************** *** 466,470 **** } ! if (headerBuffer[0] == (byte) SEQ_PREFIX.charAt(0)) { processSEQFrame(headerBuffer, amountRead, is); continue; --- 456,460 ---- } ! if (headerBuffer[0] == (byte) MESSAGE_TYPE_SEQ[0]) { processSEQFrame(headerBuffer, amountRead, is); continue; *************** *** 665,692 **** // Process the header ! StringTokenizer st = new StringTokenizer(new String(headerBuffer, 0, ! headerLength)); ! ! if (st.countTokens() != 4) { ! ! // This should just shut the session down. ! Log.logEntry(Log.SEV_ERROR, TCP_MAPPING, "Malformed BEEP header"); ! throw new BEEPException("Malformed BEEP header"); } ! // Skip the SEQ ! if (st.nextToken().equals("SEQ") == false) { ! throw new BEEPException("Malformed BEEP header"); ! } ! ! // Read the Channel Number ! int channelNum = Integer.parseInt(st.nextToken()); ! // Read the Ack Number ! long ackNum = Long.parseLong(st.nextToken()); ! ! // Read the Window Number ! int window = Integer.parseInt(st.nextToken()); // update the channel with the new receive window size --- 655,673 ---- // Process the header ! HeaderParser header = new HeaderParser(headerBuffer, ! headerLength - CRLF.length()); ! ! char[] type = header.parseType(); ! if (java.util.Arrays.equals(type, MESSAGE_TYPE_SEQ) == false) { throw new BEEPException("Malformed BEEP header"); } ! int channelNum = header.parseInt(); ! long ackNum = header.parseUnsignedInt(); ! int window = header.parseInt(); ! if (header.hasMoreTokens()) { ! throw new BEEPException("Malformed BEEP Header"); ! } // update the channel with the new receive window size |