Fix bug receiving datagrams on v3 sessions with UTF-8 IDs

Add test for tag options
This commit is contained in:
zzz
2016-02-08 17:30:01 +00:00
parent 8f667a0463
commit 55addfc739
2 changed files with 16 additions and 1 deletions

View File

@ -137,6 +137,7 @@ class SAMv3DatagramServer implements Handler {
private static class MessageDispatcher implements Runnable {
private final ByteArrayInputStream is;
private static final int MAX_LINE_LENGTH = 2*1024;
public MessageDispatcher(byte[] buf) {
this.is = new ByteArrayInputStream(buf) ;
@ -144,8 +145,21 @@ class SAMv3DatagramServer implements Handler {
public void run() {
try {
String header = DataHelper.readLine(is).trim();
// not UTF-8
//String header = DataHelper.readLine(is).trim();
// we cannot use SAMUtils.parseParams() here
final UTF8Reader reader = new UTF8Reader(is);
final StringBuilder buf = new StringBuilder(MAX_LINE_LENGTH);
int c;
int i = 0;
while ((c = reader.read()) != -1) {
if (++i > MAX_LINE_LENGTH)
throw new IOException("Line too long - max " + MAX_LINE_LENGTH);
if (c == '\n')
break;
buf.append((char)c);
}
String header = buf.toString();
StringTokenizer tok = new StringTokenizer(header, " ");
if (tok.countTokens() < 3) {
// This is not a correct message, for sure

View File

@ -513,6 +513,7 @@ public class SAMStreamSend {
baos.write(DataHelper.getUTF8(" PROTOCOL=123 TO_PORT=5678"));
else
baos.write(DataHelper.getUTF8(" TO_PORT=5678"));
baos.write(DataHelper.getUTF8(" SEND_TAGS=19 TAG_THRESHOLD=13 EXPIRES=33 SEND_LEASESET=true"));
}
baos.write((byte) '\n');
baos.write(data, 0, read);