libktorrent  2.2.0
packetsocket.h
1 /***************************************************************************
2  * Copyright (C) 2005 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 #ifndef NETBUFFEREDSOCKET_H
21 #define NETBUFFEREDSOCKET_H
22 
23 #include <deque>
24 #include <QMutex>
25 #include <net/socket.h>
26 #include <download/request.h>
27 #include <download/packet.h>
28 #include <net/trafficshapedsocket.h>
29 
30 namespace net
31 {
32  using bt::Uint8;
33  using bt::Uint32;
34 
35 
36 
37 
44  class PacketSocket : public TrafficShapedSocket
45  {
46  public:
47  PacketSocket(SocketDevice* sock);
48  PacketSocket(int fd,int ip_version);
49  PacketSocket(bool tcp,int ip_version);
50  ~PacketSocket() override;
51 
56  void addPacket(bt::Packet::Ptr packet);
57 
58 
59  Uint32 write(Uint32 max, bt::TimeStamp now) override;
60  bool bytesReadyToWrite() const override;
61 
63  Uint32 dataBytesUploaded();
64 
69  void clearPieces(bool reject);
70 
77  void doNotSendPiece(const bt::Request& req, bool reject);
78 
80  Uint32 numPendingPieceUploads() const;
81 
82  protected:
87  virtual void preProcess(bt::Packet::Ptr packet);
88 
89  private:
90  bt::Packet::Ptr selectPacket();
91 
92  protected:
93  std::deque<bt::Packet::Ptr> control_packets;
94  std::deque<bt::Packet::Ptr> data_packets; //NOTE: revert back to lists because of erase() calls?
95  bt::Packet::Ptr curr_packet;
96  Uint32 ctrl_packets_sent;
97 
98  Uint32 uploaded_data_bytes;
99  };
100 
101 }
102 
103 #endif
net::PacketSocket::clearPieces
void clearPieces(bool reject)
net::PacketSocket::doNotSendPiece
void doNotSendPiece(const bt::Request &req, bool reject)
net::PacketSocket::preProcess
virtual void preProcess(bt::Packet::Ptr packet)
net::PacketSocket::write
Uint32 write(Uint32 max, bt::TimeStamp now) override
bt::Request
Request of a piece sent to other peers.
Definition: request.h:58
net::PacketSocket::numPendingPieceUploads
Uint32 numPendingPieceUploads() const
Get the number of pending piece uploads.
net::PacketSocket::addPacket
void addPacket(bt::Packet::Ptr packet)
net::PacketSocket::bytesReadyToWrite
bool bytesReadyToWrite() const override
See if the socket has something ready to write.
net::PacketSocket::dataBytesUploaded
Uint32 dataBytesUploaded()
Get the number of data bytes uploaded.