libktorrent  2.1.1
utpserver.h
1 /***************************************************************************
2  * Copyright (C) 2009 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_UTPSERVER_H
22 #define UTP_UTPSERVER_H
23 
24 #include <QThread>
25 #include <interfaces/serverinterface.h>
26 #include <net/address.h>
27 #include <net/poll.h>
28 #include <utp/connection.h>
29 
30 
31 namespace utp
32 {
33 
37  class KTORRENT_EXPORT UTPServer : public bt::ServerInterface, public Transmitter
38  {
39  Q_OBJECT
40  public:
41  UTPServer(QObject* parent = 0);
42  ~UTPServer() override;
43 
45  void setCreateSockets(bool on);
46 
47  bool changePort(bt::Uint16 port) override;
48 
50  bool sendTo(Connection::Ptr conn, const PacketBuffer & packet) override;
51 
53  Connection::WPtr connectTo(const net::Address & addr);
54 
56  Connection::WPtr acceptedConnection();
57 
59  void start();
60 
62  void stop();
63 
65  void preparePolling(net::Poll* p, net::Poll::Mode mode, Connection::Ptr& conn);
66 
68  void setTOS(bt::Uint8 type_of_service);
69 
71  void threadStarted();
72 
77  void handlePendingConnections();
78 
79  protected:
80  virtual void handlePacket(bt::Buffer::Ptr buffer, const net::Address & addr);
81  void stateChanged(Connection::Ptr conn, bool readable, bool writeable) override;
82  void closed(Connection::Ptr conn) override;
83  void customEvent(QEvent* ev) override;
84 
85  Q_SIGNALS:
86  void handlePendingConnectionsDelayed();
88  void accepted();
89 
90  private Q_SLOTS:
91  void cleanup();
92  void checkTimeouts();
93 
94  private:
95  class Private;
96  Private* d;
97  };
98 
99 }
100 
101 #endif // UTP_UTPSERVER_H
bt::ServerInterface
Definition: serverinterface.h:58
net::Address
Definition: address.h:59
net::Poll
Definition: poll.h:64