[EMAIL PROTECTED] wrote:
> 
> [EMAIL PROTECTED] wrote:
> > [EMAIL PROTECTED] wrote:
> >> A while ago I posted a script with functions to message back and forth
> >> between two rebol scripts, but which didn't work reliably for some
> >> reason. I don't know why it didn't work, but Bo sent me an example script
> >> which I used to fix my problem. Since there was some interest I'll post
> >> this one.
> [..]
> > I've modified this so that it sends along the length of the data being
> > sent, so instead of looking for endofchar, it can use read-io directly
> > which is mucho faster :)  Only the transmit & receive functions are
> > changed, with the most damage being done in receive.
> 
> Your improvement survived my first test, and it's indeed much faster. But
> now I noticed it does not work reliably unfortunately. :(
> I managed to make it fail now, it was sending a 16 character long string,
> namely
> ["DE" 2 "AX" 25]
> and it only got
> ["DE" 2 "AX" 25
> (15 chars) with the first read-io.
> As it should, it then tried to get the last byte. But it never got it, so it
> got stuck in an endless loop trying to get this last byte. I do wonder what
> the problem is here. Oh well, I guess I'll go back to the working (but
> slow) solution. I don't know how to report this problem in a useful way
> since I can't reproduce it, it just seems to happen randomly.

ok, I think I've figured it out...

console 1 (server)
>> append outport "12345678901234567"

console 2
>> data: make string! 17
== ""
>> read-io inport data 17
== 17

So it has read the 17 characters ok.  Ok, now send 16 bytes instead of
17

console 1
>> append outport "1234567890123456"

console 2
>> data: make string! 16
== ""
>> read-io inport data 16
== 15

So trying to read-io a length that is a multiple of 16 (the same problem
happens when sending 32 bytes) causes read-io to miss the last
character.  A temporary fix is to change line 20 in netmsg.r to 

data: make string! (total-len + 1)


You can test it with something like this -

console 1
>> for i 1 256 1 [transmit head insert/dup copy "" (last to-string i) i]


console 2
>> receive-test: []
== []
>> loop 256 [append receive-test receive]
== ["1" "22" "333" "4444" "55555" "666666" "7777777" "88888888"
"999999999" "0000000000" "11111111111" "222222222222" "333333333333...
>> length? receive-test
== 256
>> length? receive-test/16
== 16
>> length? receive-test/32
== 32
>> length? receive-test/256
== 256

Julian Kinraid

Reply via email to