tlaukkan / zigbee4java

Zigbee API for Java provides simple Java interface to ZigBee network.
Apache License 2.0
143 stars 68 forks source link

"quit" commad can't quit the console application #91

Open Brhett opened 8 years ago

Brhett commented 8 years ago

The "read" method is blocking in the thread "ZToolPacketParser". Thus, "parserThread.join()" might be blocked during closing of "ZToolPacketParser".

Tested on the current head version eaf7129.

tlaukkan commented 8 years ago

Repeats still on Macbook Pro.

Brhett commented 8 years ago

The root cause should be the port implementation of libjSSC-2.8_[x86].so that the select() is blocked even if the handle was closed. A possible trick to fix this issue is adding a timeout to select() and check the return value of it. See pseudo-code below.

int ret = select(portHandle +1, &read_fd_set, NULL, NULL, &internal_timeout);
if (ret == -1)
{
    throwSerialPortException(...);
    return NULL;
}
else if (!FD_ISSET(portHandle, &read_fd_set))
{
    continue;
}