From 23eff9bc3e45950fa69258fcfcf4d2d8b397e905 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 26 Feb 2006 16:08:10 +0000 Subject: [PATCH] User setting for TCP window size --- command.cc | 16 +++++++++++++ tcp.cc | 11 ++++++--- tcp.h | 1 + vdr.cc | 5 ++++ vdr.h | 2 ++ voptions.cc | 8 +++++-- voptionsmenu.cc | 62 ++++++++++++++++++++++++++++++++++++++++++------- voptionsmenu.h | 1 + 8 files changed, 93 insertions(+), 13 deletions(-) diff --git a/command.cc b/command.cc index 7ece424..ecaf4e1 100644 --- a/command.cc +++ b/command.cc @@ -544,6 +544,22 @@ void Command::doJustConnected(VConnect* vconnect) video->setMode(Video::NORMAL); } + config = vdr->configLoad("Advanced", "TCP receive window"); + if (config) + { + size_t newTCPsize = atoi(config); + delete[] config; + + logger->log("Command", Log::INFO, "Setting TCP window size %i", newTCPsize); + vdr->setReceiveWindow(newTCPsize); + } + else + { + logger->log("Command", Log::INFO, "TCP window size not found, setting 2048"); + vdr->setReceiveWindow(2048); // Default + } + + // config done // Save power state = on diff --git a/tcp.cc b/tcp.cc index fd5444f..61a079a 100644 --- a/tcp.cc +++ b/tcp.cc @@ -72,9 +72,7 @@ int TCP::connectTo(char* host, unsigned short port) oldflags |= O_NONBLOCK; fcntl(sock, F_SETFL, oldflags); - // Set receive window - size_t rxBufferSize = 2048; - setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &rxBufferSize, sizeof(size_t)); +// setReceiveWindow(2048); // ok, how to open a connection in non blocking mode (and therefore have a self set timeout!!) @@ -146,6 +144,13 @@ The full documentation: */ } +void TCP::setReceiveWindow(size_t rxBufferSize) +{ + // Set receive window + int r = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &rxBufferSize, sizeof(size_t)); + Log::getInstance()->log("TCP", Log::DEBUG, "Set receive window to %i, success(=0): %i", rxBufferSize, r); +} + void TCP::assignSocket(int tsocket) { sock = tsocket; diff --git a/tcp.h b/tcp.h index 4a024c7..19ad1c0 100644 --- a/tcp.h +++ b/tcp.h @@ -60,6 +60,7 @@ class TCP static void dump(unsigned char* data, ULONG size); void getMAC(char* dest); // copies 6 MAC bytes to dest + void setReceiveWindow(size_t rxBufferSize); private: int sock; diff --git a/vdr.cc b/vdr.cc index 3f8c7e7..79481b8 100644 --- a/vdr.cc +++ b/vdr.cc @@ -152,6 +152,11 @@ void VDR::disconnect() Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect"); } +void VDR::setReceiveWindow(size_t size) +{ + tcp->setReceiveWindow(size); +} + /////////////////////////////////////////////////////// int VDR::getPacket() diff --git a/vdr.h b/vdr.h index 5622fd0..7809054 100644 --- a/vdr.h +++ b/vdr.h @@ -108,6 +108,8 @@ class VDR void disconnect(); ULLONG getResumePoint(char* fileName); // uses configLoad + void setReceiveWindow(size_t size); + // protocol functions int doLogin(); diff --git a/voptions.cc b/voptions.cc index 0d03d2a..a2d2246 100644 --- a/voptions.cc +++ b/voptions.cc @@ -28,7 +28,11 @@ VOptions::VOptions(View* tparent, const char* title, const OPTIONDATA* toptionDa optionData = toptionData; numOptions = tnumOptions; - create(530, 85 + (numOptions * 30)); + UINT newHeight = 85; + if (numOptions < 4) newHeight += (4 * 30); + else newHeight += (numOptions * 30); + + create(530, newHeight); setBackgroundColour(Colour::VIEWBACKGROUND); setTitleBarOn(1); @@ -130,7 +134,7 @@ void VOptions::draw() WSymbol wsy; Colour cl; - drawText(tr("Press back to exit, <, > or [ok] to change"), 10, 55+numOptions*30, Colour::LIGHTTEXT); + drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, Colour::LIGHTTEXT); wsy.setSurface(surface); diff --git a/voptionsmenu.cc b/voptionsmenu.cc index f0ef93b..06c5a65 100644 --- a/voptionsmenu.cc +++ b/voptionsmenu.cc @@ -24,7 +24,7 @@ VOptionsMenu::VOptionsMenu() { viewman = ViewMan::getInstance(); - create(460, 190); + create(460, 200); if (Video::getInstance()->getFormat() == Video::PAL) { setScreenPos(140, 170); @@ -47,7 +47,7 @@ VOptionsMenu::VOptionsMenu() wb = new WButton(); wb->setText("General"); wb->setSurface(surface); - wb->setSurfaceOffset(160, 70); + wb->setSurfaceOffset(160, 60); wb->setDimensions(140, fontHeight); wb->setTag(1); buttons.push_back(wb); @@ -55,11 +55,20 @@ VOptionsMenu::VOptionsMenu() wb = new WButton(); wb->setText("Timers"); wb->setSurface(surface); - wb->setSurfaceOffset(160, 110); + wb->setSurfaceOffset(160, 100); wb->setDimensions(140, fontHeight); wb->setTag(2); buttons.push_back(wb); + wb = new WButton(); + wb->setText("Advanced"); + wb->setSurface(surface); + wb->setSurfaceOffset(160, 140); + wb->setDimensions(140, fontHeight); + wb->setTag(3); + buttons.push_back(wb); + + selectedButton = buttons.begin(); (*selectedButton)->setActive(1); } @@ -120,6 +129,7 @@ int VOptionsMenu::handleCommand(int command) { case 1: doGeneral(); break; case 2: doTimers(); break; + case 3: doAdvanced(); break; } return 2; } @@ -210,6 +220,22 @@ void VOptionsMenu::doApplyChanges(map* changedOptions) } break; } + case 13: + { + size_t newTCPsize = 2048; + + if (i->second == 0) newTCPsize = 1024; + else if (i->second == 1) newTCPsize = 2048; + else if (i->second == 2) newTCPsize = 4096; + else if (i->second == 3) newTCPsize = 8192; + else if (i->second == 4) newTCPsize = 16384; + else if (i->second == 5) newTCPsize = 32768; + else if (i->second == 6) newTCPsize = 65536; + + Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize); + vdr->setReceiveWindow(newTCPsize); + break; + } } } @@ -219,7 +245,7 @@ void VOptionsMenu::doApplyChanges(map* changedOptions) void VOptionsMenu::doGeneral() { - static const int numOptions = 8; + static const int numOptions = 7; static const char* options1[] = {"Old", "New"}; static const char* options3[] = {"RGB+composite", "S-Video"}; @@ -237,13 +263,12 @@ void VOptionsMenu::doGeneral() {5, "16:9 on 4:3 display mode", "TV", "Widemode", OPTIONTYPE_TEXT, 2, 0, 0, options5 }, {6, "Power state after bootup", "General", "Power After Boot", OPTIONTYPE_TEXT, 3, 0, 0, options6 }, {7, "Display channels", "General", "Channels", OPTIONTYPE_TEXT, 2, 0, 0, options7 }, - {8, "VDR-Pri 0=OK !See forums!","General", "Live priority", OPTIONTYPE_INT, 100, 0, 0, NULL } }; // As all the above data is const static, it can be sent to the new View, this stack frame can // quit and the pointers will all still be valid. I think. (Hope). - VOptions* v = new VOptions(this, "General Options", optionData, numOptions); + VOptions* v = new VOptions(this, tr("General Options"), optionData, numOptions); v->draw(); viewman->add(v); viewman->updateView(v); @@ -259,13 +284,34 @@ void VOptionsMenu::doTimers() {9, "Default start margin (minutes)", "Timers", "Start margin", OPTIONTYPE_INT, 20, 5, 0, NULL }, {10, "Default end margin (minutes)", "Timers", "End margin", OPTIONTYPE_INT, 20, 5, 0, NULL }, {11, "Default priority", "Timers", "Priority", OPTIONTYPE_INT, 100, 99, 0, NULL }, - {12, "Default lifetime", "Timers", "Lifetime", OPTIONTYPE_INT, 100, 99, 0, NULL } + {12, "Default lifetime", "Timers", "Lifetime", OPTIONTYPE_INT, 100, 99, 0, NULL }, + }; + + // As all the above data is const static, it can be sent to the new View, this stack frame can + // quit and the pointers will all still be valid. I think. (Hope). + + VOptions* v = new VOptions(this, tr("Timer Options"), optionData, numOptions); + v->draw(); + viewman->add(v); + viewman->updateView(v); +} + +void VOptionsMenu::doAdvanced() +{ + static const int numOptions = 2; + + static const char* options13[] = {"1024", "2048", "4096", "8192", "16384", "32768", "65536"}; + + const static OPTIONDATA optionData[numOptions] = + { + {8, "VDR-Pri 0=OK !See forums!", "General", "Live priority", OPTIONTYPE_INT, 100, 0, 0, NULL }, + {13, "TCP receive window size", "Advanced", "TCP receive window", OPTIONTYPE_TEXT, 7, 1, 0, options13 } }; // As all the above data is const static, it can be sent to the new View, this stack frame can // quit and the pointers will all still be valid. I think. (Hope). - VOptions* v = new VOptions(this, "Timer Options", optionData, numOptions); + VOptions* v = new VOptions(this, tr("Advanced Options"), optionData, numOptions); v->draw(); viewman->add(v); viewman->updateView(v); diff --git a/voptionsmenu.h b/voptionsmenu.h index fb1cf08..f8cf20e 100644 --- a/voptionsmenu.h +++ b/voptionsmenu.h @@ -47,6 +47,7 @@ class VOptionsMenu : public View private: void doGeneral(); void doTimers(); + void doAdvanced(); void doApplyChanges(map* changedOptions); VDR* vdr; -- 2.39.5