Hi,
I have tested “read” from file descriptor and I have noticed serious issue. Please look at code below:
int Gps::OpenNMEA()
{
int FD = open("/dev/nmea", O_RDONLY);
le_fdMonitor_Create("Nmea", FD, NmeaHandler, POLLIN);
return FD;
}
void Gps::NmeaHandler(int FD, short Event)
{
if (Event & POLLIN)
{
char Buff[10];
std::string Res;
ssize_t BytesRead = read(FD, Buff, 10);
if(BytesRead > 10)
{
std::string Err = "ERROR. Read bytes:";
Err.append(std::to_string(BytesRead));
LE_INFO(Err.c_str());
}
Res.append(Buff, BytesRead);
LE_INFO(Res.c_str());
}
}
The error should not happened because ‘read’ function should read max 10 bytes. However function ‘read’ reads much more bytes (in this case 548 bytes). Initially my buffer was 1024 big and I did not solve the problem because ‘read’ function was reading 4000-8000 bytes.
Nov 22 22:22:08 | mod[12951]/Component T=main | Gps.cpp NmeaHandler() 104 | ERROR. Read bytes:548
Nov 22 22:22:08 | mod[12951]/Component T=main | Gps.cpp NmeaHandler() 109 | $GPGSV,4,1,13,02�+^E
Does someone know why the function behave like this?