Pierre Ossman | c09e558 | 2015-12-11 20:23:17 +0100 | [diff] [blame^] | 1 | /* Copyright 2009-2015 Pierre Ossman for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __RFB_CONGESTION_H__ |
| 20 | #define __RFB_CONGESTION_H__ |
| 21 | |
| 22 | #include <list> |
| 23 | |
| 24 | #include <rfb/Timer.h> |
| 25 | |
| 26 | namespace rfb { |
| 27 | class Congestion : public Timer::Callback { |
| 28 | public: |
| 29 | Congestion(); |
| 30 | ~Congestion(); |
| 31 | |
| 32 | // sentPing() must be called when a marker is placed on the |
| 33 | // outgoing stream, along with the current stream position. |
| 34 | // gotPong() must be called when the response for such a marker |
| 35 | // is received. |
| 36 | void sentPing(int offset); |
| 37 | void gotPong(); |
| 38 | |
| 39 | // isCongested() determines if the transport is currently congested |
| 40 | // or if more data can be sent. The curren stream position and how |
| 41 | // long the transport has been idle must be specified. |
| 42 | bool isCongested(int offset, unsigned idleTime); |
| 43 | |
| 44 | private: |
| 45 | // Timer callbacks |
| 46 | virtual bool handleTimeout(Timer* t); |
| 47 | |
| 48 | private: |
| 49 | unsigned baseRTT; |
| 50 | unsigned congWindow; |
| 51 | unsigned ackedOffset, sentOffset; |
| 52 | |
| 53 | unsigned minRTT; |
| 54 | bool seenCongestion; |
| 55 | Timer congestionTimer; |
| 56 | |
| 57 | struct RTTInfo; |
| 58 | std::list<struct RTTInfo> pings; |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | #endif |