| 67 | } |
| 68 | |
| 69 | bool FiberStreamSocketImpl::pollImpl(Poco::Timespan & timeout, int mode) |
| 70 | { |
| 71 | uint32_t events = 0; |
| 72 | if (mode & SELECT_READ) |
| 73 | events |= POLLIN; |
| 74 | if (mode & SELECT_WRITE) |
| 75 | events |= POLLOUT; |
| 76 | if (mode & SELECT_ERROR) |
| 77 | events |= POLLERR; |
| 78 | |
| 79 | uint64_t triggered = 0; |
| 80 | silk::FiberScheduler::IoFuture poll_future; |
| 81 | silk::FiberScheduler::poll(sockfd(), events, &triggered, &poll_future); |
| 82 | |
| 83 | const Poco::Timestamp started; |
| 84 | int r = 0; |
| 85 | const Poco::Timestamp::TimeDiff timeout_us = timeout.totalMicroseconds(); |
| 86 | if (timeout_us >= 0) |
| 87 | { |
| 88 | r = silk::FiberFuture::waitWithTimeout(&poll_future, static_cast<uint64_t>(timeout_us) * 1000); |
| 89 | if (r == ETIMEDOUT) |
| 90 | { |
| 91 | poll_future.cancel(); |
| 92 | (void)poll_future.wait(); |
| 93 | timeout = 0; |
| 94 | return false; |
| 95 | } |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | r = poll_future.wait(); |
| 100 | } |
| 101 | |
| 102 | const Poco::Timespan elapsed = Poco::Timestamp() - started; |
| 103 | timeout = (elapsed < timeout) ? (timeout - elapsed) : Poco::Timespan(0); |
| 104 | |
| 105 | if (r) |
| 106 | error(r, "poll"); |
| 107 | |
| 108 | return triggered != 0; |
| 109 | } |
| 110 | |
| 111 | int FiberStreamSocketImpl::sendBytes(const void * buffer, int length, int flags) |
| 112 | { |