libktorrent  2.2.0
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 
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
utp::UTPServer::connectTo
Connection::WPtr connectTo(const net::Address &addr)
Setup a connection to a remote address.
bt::ServerInterface
Definition: serverinterface.h:40
utp::UTPServer::setCreateSockets
void setCreateSockets(bool on)
Enabled creating sockets (tests need to have this disabled)
utp::UTPServer::accepted
void accepted()
Emitted when a connection is accepted if creating sockets is disabled.
utp::UTPServer::acceptedConnection
Connection::WPtr acceptedConnection()
Get the last accepted connection (Note: for unittest purposes)
net::Address
Definition: address.h:41
utp::UTPServer::start
void start()
Start the UTP server.
utp::UTPServer::stop
void stop()
Stop the UTP server.
utp::UTPServer::changePort
bool changePort(bt::Uint16 port) override
utp::Transmitter
Definition: connection.h:210
utp::UTPServer
Definition: utpserver.h:38
utp::UTPServer::sendTo
bool sendTo(Connection::Ptr conn, const PacketBuffer &packet) override
Send a packet to some host.
utp::UTPServer::handlePendingConnections
void handlePendingConnections()
utp::UTPServer::setTOS
void setTOS(bt::Uint8 type_of_service)
Set the TOS byte.
utp::UTPServer::threadStarted
void threadStarted()
Thread has been started.
utp::PacketBuffer
Definition: packetbuffer.h:38
utp::UTPServer::stateChanged
void stateChanged(Connection::Ptr conn, bool readable, bool writeable) override
Connection has become readable, writeable or both.
net::Poll
Definition: poll.h:64
utp::UTPServer::closed
void closed(Connection::Ptr conn) override
Called when the connection is closed.
utp::UTPServer::preparePolling
void preparePolling(net::Poll *p, net::Poll::Mode mode, Connection::Ptr &conn)
Prepare the server for polling.