21 #ifndef UTP_CONNECTION_H
22 #define UTP_CONNECTION_H
26 #include <QWaitCondition>
27 #include <QBasicTimer>
28 #include <QSharedPointer>
29 #include <ktorrent_export.h>
30 #include <net/address.h>
31 #include <utp/utpprotocol.h>
32 #include <util/circularbuffer.h>
33 #include <util/timer.h>
34 #include <utp/remotewindow.h>
35 #include <boost/concept_check.hpp>
72 ConnectionState state;
73 bt::Uint16 send_connection_id;
74 bt::Uint32 reply_micro;
75 bt::Uint16 recv_connection_id;
82 bt::Uint32 packet_size;
83 bt::Uint32 last_window_size_transmitted;
85 bt::Uint64 bytes_received;
86 bt::Uint64 bytes_sent;
87 bt::Uint32 packets_received;
88 bt::Uint32 packets_sent;
89 bt::Uint64 bytes_lost;
90 bt::Uint32 packets_lost;
121 int send(
const bt::Uint8* data, bt::Uint32 len);
124 int recv(bt::Uint8* buf, bt::Uint32 max_len);
151 void updateRTT(
const Header* hdr, bt::Uint32 packet_rtt, bt::Uint32 packet_size)
override;
162 typedef QSharedPointer<Connection> Ptr;
163 typedef QWeakPointer<Connection> WPtr;
176 void updateDelayMeasurement(
const Header* hdr);
177 void sendStateOrData();
179 void sendPacket(bt::Uint32 type, bt::Uint16 p_ack_nr);
180 void checkIfClosed();
184 bt::Uint32 extensionLength()
const;
185 void handleTimeout();
193 mutable QMutex mutex;
194 QWaitCondition connected;
195 QWaitCondition data_ready;
200 Connection::WPtr
self;
218 virtual void stateChanged(Connection::Ptr conn,
bool readable,
bool writeable) = 0;
221 virtual void closed(Connection::Ptr conn) = 0;
226 #endif // UTP_CONNECTION_H
void checkTimeout(const TimeValue &now)
Check if we haven't hit a timeout yet.
void reset()
Reset the connection.
void updateRTT(const Header *hdr, bt::Uint32 packet_rtt, bt::Uint32 packet_size) override
Update the RTT time.
virtual void closed(Connection::Ptr conn)=0
Called when the connection is closed.
const net::Address & remoteAddress() const
Get the remote address.
bool waitUntilConnected()
Wait until the connectTo call fails or succeeds.
bt::Uint16 receiveConnectionID() const
Get the receive connection id.
const Stats & connectionStats() const
Get the connection stats.
bool isWriteable() const
Can we write to this socket.
bt::Uint32 currentTimeout() const override
Get the current timeout.
virtual void stateChanged(Connection::Ptr conn, bool readable, bool writeable)=0
Connection has become readable, writeable or both.
int send(const bt::Uint8 *data, bt::Uint32 len)
Send some data, returns the amount of bytes sent (or -1 on error)
ConnectionState connectionState() const
Get the connection state.
virtual bool sendTo(Connection::Ptr conn, const PacketBuffer &packet)=0
Send a packet of a connection.
bool allDataSent() const
Is all data sent.
void startConnecting()
Start connecting (OUTGOING only)
void dumpStats()
Dump connection stats.
Type connectionType() const
Get the type of connection.
ConnectionState handlePacket(const PacketParser &parser, bt::Buffer::Ptr packet)
Handle a single packet.
void setBlocking(bool on)
Turn on or off blocking mode.
void retransmit(PacketBuffer &packet, bt::Uint16 p_seq_nr) override
Retransmit a packet.
int recv(bt::Uint8 *buf, bt::Uint32 max_len)
Read available data from local window, returns the amount of bytes read.
void close()
Close the socket.
void setWeakPointer(WPtr ptr)
Set a weak pointer to self.
bt::Uint32 bytesAvailable() const
Get the number of bytes available.
Thrown when a transmission error occurs, server should kill the connection if it happens.
bool waitForData(bt::Uint32 timeout=0)
Wait until there is data ready or the socket is closed or a timeout occurs.