summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2012-03-04 21:27:42 -0500
committerNat Goodspeed <nat@lindenlab.com>2012-03-04 21:27:42 -0500
commit30e8e23d7cf666c406901d85a59d16401dca67ab (patch)
tree1125b5ade5e1db59a7db6e64d619f23edd8564fb /indra/llcommon/tests
parentca703b2b9cd9469ad86539f2b95dbf1162b786f2 (diff)
Simplify llleap_test.cpp plugin by reading individual characters.
While we're accumulating the 'length:' prefix, the present socket-based logic reads 20 characters, then reads 'length' more, then discards any excess (in case the whole 'length:data' packet ends up being less than 20 characters). That's probably a bug: whatever characters follow that packet, however short it may be, are probably the 'length:' prefix of the next packet. We probably only get away with it because we probably never send packets that short. Earlier llleap_test.cpp plugin logic still read 20 characters, then, if there were any left after the present packet, cached them as the start of the next packet. This is probably more correct, but complicated. Easier just to read individual characters until we've seen 'length:', then try for exactly the specified length over however many reads that requires.
Diffstat (limited to 'indra/llcommon/tests')
-rw-r--r--indra/llcommon/tests/llleap_test.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/indra/llcommon/tests/llleap_test.cpp b/indra/llcommon/tests/llleap_test.cpp
index 677f4830ea..73d7217608 100644
--- a/indra/llcommon/tests/llleap_test.cpp
+++ b/indra/llcommon/tests/llleap_test.cpp
@@ -101,32 +101,25 @@ namespace tut
" sys.path.insert(0,\n"
" os.path.join(mydir, os.pardir, os.pardir, 'lib', 'python'))\n"
" from indra.base import llsd\n"
- "LEFTOVER = ''\n"
"class ProtocolError(Exception):\n"
" pass\n"
"def get():\n"
- " global LEFTOVER\n"
- " hdr = LEFTOVER\n"
- " if ':' not in hdr:\n"
- " hdr += sys.stdin.read(20)\n"
+ " hdr = ''\n"
+ " while ':' not in hdr and len(hdr) < 20:\n"
+ " hdr += sys.stdin.read(1)\n"
" if not hdr:\n"
" sys.exit(0)\n"
- " parts = hdr.split(':', 1)\n"
- " if len(parts) != 2:\n"
+ " if not hdr.endswith(':'):\n"
" raise ProtocolError('Expected len:data, got %r' % hdr)\n"
" try:\n"
- " length = int(parts[0])\n"
+ " length = int(hdr[:-1])\n"
" except ValueError:\n"
- " raise ProtocolError('Non-numeric len %r' % parts[0])\n"
- " del parts[0]\n"
- " received = len(parts[0])\n"
+ " raise ProtocolError('Non-numeric len %r' % hdr[:-1])\n"
+ " parts = []\n"
+ " received = 0\n"
" while received < length:\n"
" parts.append(sys.stdin.read(length - received))\n"
" received += len(parts[-1])\n"
- " if received > length:\n"
- " excess = length - received\n"
- " LEFTOVER = parts[-1][excess:]\n"
- " parts[-1] = parts[-1][:excess]\n"
" data = ''.join(parts)\n"
" assert len(data) == length\n"
" try:\n"