~ubuntu-branches/ubuntu/oneiric/libktorrent/oneiric

« back to all changes in this revision

Viewing changes to src/peer/packetreader.h

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2011-05-26 00:33:38 UTC
  • mfrom: (5.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110526003338-2r4zwyzn8bovsxay
Tags: 1.1.1-2
Release to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        };
40
40
 
41
41
        /**
42
 
        @author Joris Guisson
 
42
         * Chops up the raw byte stream from a socket into bittorrent packets
 
43
         * @author Joris Guisson
43
44
        */
44
45
        class PacketReader : public net::SocketReader
45
46
        {
46
 
                Peer* peer;
47
 
                bool error;
48
 
                QList<IncomingPacket*> packet_queue;
49
 
                QMutex mutex;
50
 
                Uint8 len[4];
51
 
                int len_received;
 
47
                
52
48
        public:
53
 
                PacketReader(Peer* peer);
 
49
                PacketReader(Peer* peer,Uint32 max_packet_size);
54
50
                virtual ~PacketReader();
55
51
                
 
52
                /**
 
53
                 * Push packets to Peer (runs in main thread)
 
54
                 */
56
55
                void update();
 
56
                
 
57
                /// Did an error occur
57
58
                bool ok() const {return !error;}
 
59
                
58
60
        private:
59
61
                Uint32 newPacket(Uint8* buf,Uint32 size);
60
62
                Uint32 readPacket(Uint8* buf,Uint32 size);
61
63
                virtual void onDataReady(Uint8* buf,Uint32 size);
62
64
                IncomingPacket* dequeuePacket();
 
65
                
 
66
        private:
 
67
                Peer* peer;
 
68
                bool error;
 
69
                QList<IncomingPacket*> packet_queue;
 
70
                QMutex mutex;
 
71
                Uint8 len[4];
 
72
                int len_received;
 
73
                Uint32 max_packet_size;
63
74
        };
64
75
 
65
76
}