libktorrent  2.2.0
pollpipe.h
1 /***************************************************************************
2  * Copyright (C) 2010 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef UTP_POLLPIPE_H
22 #define UTP_POLLPIPE_H
23 
24 #include <bitset>
25 #include <net/poll.h>
26 #include <net/wakeuppipe.h>
27 
28 
29 namespace utp
30 {
31 
35  class PollPipe : public net::WakeUpPipe
36  {
37  public:
38  PollPipe(net::Poll::Mode mode);
39  ~PollPipe() override;
40 
41  typedef QSharedPointer<PollPipe> Ptr;
42 
44  bool polling() const {return poll_index >= 0;}
45 
47  void prepare(net::Poll* p, bt::Uint16 conn_id, PollPipe::Ptr self)
48  {
49  QMutexLocker lock(&mutex);
50  conn_ids.set(conn_id, true);
51  if (poll_index < 0)
52  poll_index = p->add(qSharedPointerCast<PollClient>(self));
53  }
54 
56  bool polling(bt::Uint16 conn) const
57  {
58  QMutexLocker lock(&mutex);
59  return poll_index >= 0 && conn_ids[conn];
60  }
61 
63  void reset() override;
64 
66  net::Poll::Mode pollingMode() const {return mode;}
67 
68  private:
69  net::Poll::Mode mode;
70  int poll_index;
71  std::bitset<65536> conn_ids;
72  };
73 
74 
75 }
76 
77 #endif // UTP_POLLPIPE_H
net::Poll::add
int add(int fd, Mode mode)
Add a file descriptor to the poll (returns the index of it)
utp::PollPipe::reset
void reset() override
Reset the poll_index.
utp::PollPipe::polling
bool polling() const
Is the pipe being polled.
Definition: pollpipe.h:80
net::WakeUpPipe
Definition: wakeuppipe.h:56
utp::PollPipe::pollingMode
net::Poll::Mode pollingMode() const
Polling mode.
Definition: pollpipe.h:102
utp::PollPipe::prepare
void prepare(net::Poll *p, bt::Uint16 conn_id, PollPipe::Ptr self)
Prepare the poll.
Definition: pollpipe.h:83
net::Poll
Definition: poll.h:64