File indexing completed on 2025-01-05 04:37:33
0001 /* 0002 SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef UTP_POLLPIPE_H 0008 #define UTP_POLLPIPE_H 0009 0010 #include <bitset> 0011 #include <net/poll.h> 0012 #include <net/wakeuppipe.h> 0013 0014 namespace utp 0015 { 0016 /** 0017 Special wake up pipe for UTP polling 0018 */ 0019 class PollPipe : public net::WakeUpPipe 0020 { 0021 public: 0022 PollPipe(net::Poll::Mode mode); 0023 ~PollPipe() override; 0024 0025 typedef QSharedPointer<PollPipe> Ptr; 0026 0027 /// Is the pipe being polled 0028 bool polling() const 0029 { 0030 return poll_index >= 0; 0031 } 0032 0033 /// Prepare the poll 0034 void prepare(net::Poll *p, bt::Uint16 conn_id, PollPipe::Ptr self) 0035 { 0036 QMutexLocker lock(&mutex); 0037 conn_ids.set(conn_id, true); 0038 if (poll_index < 0) 0039 poll_index = p->add(qSharedPointerCast<PollClient>(self)); 0040 } 0041 0042 /// Are we polling a connection 0043 bool polling(bt::Uint16 conn) const 0044 { 0045 QMutexLocker lock(&mutex); 0046 return poll_index >= 0 && conn_ids[conn]; 0047 } 0048 0049 /// Reset the poll_index 0050 void reset() override; 0051 0052 /// Polling mode 0053 net::Poll::Mode pollingMode() const 0054 { 0055 return mode; 0056 } 0057 0058 private: 0059 net::Poll::Mode mode; 0060 int poll_index; 0061 std::bitset<65536> conn_ids; 0062 }; 0063 0064 } 0065 0066 #endif // UTP_POLLPIPE_H