libktorrent  2.2.0
serversocket.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 
22 #ifndef NET_SERVERSOCKET_H
23 #define NET_SERVERSOCKET_H
24 
25 #include <QObject>
26 #include <QSharedPointer>
27 #include <ktorrent_export.h>
28 #include <util/constants.h>
29 #include <util/bufferpool.h>
30 
31 namespace net
32 {
33  class Address;
34 
35 
36 
41  class KTORRENT_EXPORT ServerSocket : public QObject
42  {
43  Q_OBJECT
44  public:
45  typedef QSharedPointer<ServerSocket> Ptr;
46 
51  class KTORRENT_EXPORT ConnectionHandler
52  {
53  public:
54  virtual ~ConnectionHandler() {}
55 
61  virtual void newConnection(int fd,const net::Address & addr) = 0;
62  };
63 
67  class KTORRENT_EXPORT DataHandler
68  {
69  public:
70  virtual ~DataHandler() {}
71 
77  virtual void dataReceived(bt::Buffer::Ptr buffer,const net::Address & addr) = 0;
78 
83  virtual void readyToWrite(net::ServerSocket* sock) = 0;
84  };
85 
91 
96  ServerSocket(DataHandler* dhandler);
97 
98  ~ServerSocket() override;
99 
106  bool bind(const QString & ip,bt::Uint16 port);
107 
113  bool bind(const net::Address & addr);
114 
122  int sendTo(const QByteArray & data,const net::Address & addr);
123 
132  int sendTo(const bt::Uint8* buf,int size,const net::Address & addr);
133 
138  void setWriteNotificationsEnabled(bool on);
139 
144  void setReadNotificationsEnabled(bool on);
145 
151  bool setTOS(unsigned char type_of_service);
152 
153  private Q_SLOTS:
154  void readyToAccept(int fd);
155  void readyToRead(int fd);
156  void readyToWrite(int fd);
157 
158  private:
159  class Private;
160  Private* d;
161  };
162 
163 }
164 
165 #endif // NET_SERVERSOCKET_H
net::Address
Definition: address.h:59
net::ServerSocket::DataHandler
Definition: serversocket.h:86
net::ServerSocket::ConnectionHandler
Definition: serversocket.h:70
net::ServerSocket
Definition: serversocket.h:60