本文整理汇总了C++中asynciovector::iterator::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::poll方法的具体用法?C++ iterator::poll怎么用?C++ iterator::poll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asynciovector::iterator
的用法示例。
在下文中一共展示了iterator::poll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: asyncWrite
int eDVBRecordFileThread::asyncWrite(int len)
{
#ifdef SHOW_WRITE_TIME
struct timeval starttime;
struct timeval now;
suseconds_t diff;
gettimeofday(&starttime, NULL);
#endif
m_ts_parser.parseData(m_current_offset, m_buffer, len);
#ifdef SHOW_WRITE_TIME
gettimeofday(&now, NULL);
diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
eDebug("[eFilePushThreadRecorder] m_ts_parser.parseData: %9u us", (unsigned int)diff);
gettimeofday(&starttime, NULL);
#endif
int r = m_current_buffer->start(m_fd_dest, m_current_offset, len, m_buffer);
if (r < 0)
{
eDebug("[eDVBRecordFileThread] aio_write failed: %m");
return r;
}
m_current_offset += len;
#ifdef SHOW_WRITE_TIME
gettimeofday(&now, NULL);
diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
eDebug("[eFilePushThreadRecorder] aio_write: %9u us", (unsigned int)diff);
#endif
// Count how many buffers are still "busy". Move backwards from current,
// because they can reasonably be expected to finish in that order.
AsyncIOvector::iterator i = m_current_buffer;
r = i->poll();
int busy_count = 0;
while (r > 0)
{
++busy_count;
if (i == m_aio.begin())
i = m_aio.end();
--i;
if (i == m_current_buffer)
{
eDebug("[eFilePushThreadRecorder] Warning: All write buffers busy");
break;
}
r = i->poll();
if (r < 0)
return r;
}
++m_buffer_use_histogram[busy_count];
++m_current_buffer;
if (m_current_buffer == m_aio.end())
m_current_buffer = m_aio.begin();
m_buffer = m_current_buffer->buffer;
return len;
}
示例2: writeData
int eDVBRecordStreamThread::writeData(int len)
{
len = asyncWrite(len);
if (len < 0)
return len;
// Cancel aio on this buffer before returning, streams should not be held up. So we CANCEL
// any request that hasn't finished on the second round.
int r = m_current_buffer->cancel(m_fd_dest);
switch (r)
{
//case 0: // that's one of these two:
case AIO_CANCELED:
case AIO_ALLDONE:
break;
case AIO_NOTCANCELED:
eDebug("[eDVBRecordStreamThread] failed to cancel, killing all waiting IO");
aio_cancel(m_fd_dest, NULL);
// Poll all open requests, because they are all in error state now.
for (AsyncIOvector::iterator it = m_aio.begin(); it != m_aio.end(); ++it)
{
it->poll();
}
break;
case -1:
eDebug("[eDVBRecordStreamThread] failed: %m");
return r;
}
// we want to have a consistent state, so wait for completion, just to be sure
r = m_current_buffer->wait();
if (r < 0)
{
eDebug("[eDVBRecordStreamThread] wait failed: %m");
return -1;
}
return len;
}