lmahdi / as3-arduino-connector

Automatically exported from code.google.com/p/as3-arduino-connector
0 stars 0 forks source link

onData events ma be lost with readByte() #36

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run extensive communication

What is the expected output? What do you see instead?
onData events should not be lost.

What version of the product are you using? On what operating system?
1.5.0

Please provide any additional information below.

FREObject getByte(FREContext ctx, void* funcData, uint32_t argc, FREObject 
argv[])
{
  FREObject result;

  pthread_mutex_lock( &safety);
    FRENewObjectFromUint32(buffer[0], &result);

    if ( buffer > 0 )
    {
        memcpy(buffer,buffer+1,bufferSize-1);
        bufferSize--;
    }
    if (bufferSize == 0)
      {
        sentEvent = 0;
      }
  pthread_mutex_unlock( &safety);

  return result;
}

sendEvent is reset only after last byte is read from the buffer.

It is possible that data is coming between bytesAvailable() check and exit from 
the event handler. OnData event will not be sent anymore because application 
did not read all the data from the buffer.

Fix: set sentEvent=0 in each readByte() without checking bufferSize.

Original issue reported on code.google.com by romanlut...@gmail.com on 11 Apr 2015 at 1:00

GoogleCodeExporter commented 8 years ago
This project has been moved to GitHub by Google Code.  
https://github.com/quetwo/as3-arduino-connector  Would you mind submitting a 
pull request there to correct these issues?  I would love to include them in a 
new release.

Original comment by Nicholas...@gmail.com on 14 Apr 2015 at 10:01