Hello Group:
I was wondering if somebody got some ideas on the following problem
we have.
We do open a serial port and then we open a thread to start
reading characters and put in a mailbox buffer.
Snippet code will be something like..
/* Open write/read
serial port */
fd = open(portName,
O_RDWR /*
As read and write */
| O_NOCTTY /*
Doesn't want to be the "controlling terminal" for that port */
| O_SYNC);
Then we open the thread and start reading using blocking
mode:
pthread_create(&threadId, NULL,
HandleBlockReceivedTask, (void *)this);
void CSerialPort::HandleBlockReceived() {
UCHAR buf;
int amount;
USHORT data;
/* Ensure blocking
mode */
fcntl(fd, F_SETFL, 0);
while (enable)
{
amount = read(fd, &buf, 1); ç====== block call
Here is problem, everything works ok except when we want to
close the serial port.
We want to unblock the serial port ‘read’ and
have the thread to finish.
We have try many different things to the file descriptor,
like close the file, changing the blocking mode, opening the port again,etc..
What would be the right way to force the read to return with
a -1 ( or EOF) to allow the thread to finish as a good citizen..?
Thanks in advance,
Rodrigo.