本文整理汇总了C++中FIFO::Put方法的典型用法代码示例。如果您正苦于以下问题:C++ FIFO::Put方法的具体用法?C++ FIFO::Put怎么用?C++ FIFO::Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FIFO
的用法示例。
在下文中一共展示了FIFO::Put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: threadLoop
void SerialPort::threadLoop()
{
const int fd = m_fd;
const int max_fd = fd+1;
m_running = true;
m_rxErrors[1] = 0;
while (true) {
fd_set rfds;
FD_ZERO( &rfds);
FD_SET(fd, &rfds);
struct timeval timeout;
timeout.tv_sec = kReadTimeoutMs/1000;
timeout.tv_usec = (kReadTimeoutMs%1000)*1000;
int n = select(max_fd, &rfds, 0, 0, &timeout);
// int fdset = FD_ISSET(fd, &rfds);
// printf( "fdset %i, n %i, errno %i\n", fdset, n, errno );
if ( m_open ){
if ((n > 0) && FD_ISSET(fd, &rfds)) {
// printf("poll input\n");
int nr = 0;
// while (true) {
if ( m_open ){
int n2 = read(fd, m_rxbuffer, kBufferSize);
// printf("read %d, errno %i, errbadf %i, %i, %i\n", n2, errno, EBADF, EAGAIN, EIO);
if (n2 > 0) {
// write data to ringbuffer
for (int i=0; i < n2; ++i) {
if (!m_rxfifo.Put(m_rxbuffer[i])) {
m_rxErrors[1]++;
break;
}
}
nr += n2;
} else if ((n2 == 0) && (n == 1) ) { // added by nescivi, to check for disconnected device. In this case the read is 0 all the time and otherwise eats up the CPU
// printf( "done\n" );
goto done;
} else if ((n2 == 0) || ((n2 == -1) && (errno == EAGAIN))) {
// printf( "break\n");
break;
} else {
#ifndef NDEBUG
printf("SerialPort HUP\n");
#endif
goto done;
}
}
//}
if (!m_running) {
// close and cleanup
goto done;
}
if (nr > 0) {
dataAvailable();
}
} else if (n == -1) {
goto done;
}
}
if (!m_running) {
// close and cleanup
goto done;
}
}
done:
// doneAction();
if ( m_open ){
tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &m_oldtermio);
close(fd);
};
m_open = false;
m_running = false;
if ( m_dodone )
doneAction();
#ifndef NDEBUG
printf("SerialPort closed\n");
#endif
}