From: Victor Grishchenko Date: Thu, 4 Feb 2010 13:48:40 +0000 (+0100) Subject: Added Channel::Close() X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=b6eeab834758969e7c7e764e8396cf4389d3740f;p=swift-upb.git Added Channel::Close() --- diff --git a/send_control.cpp b/send_control.cpp index 11b9110..7fb12d5 100644 --- a/send_control.cpp +++ b/send_control.cpp @@ -28,6 +28,7 @@ tint Channel::NextSendTime () { case SLOW_START_CONTROL: return SlowStartNextSendTime(); case AIMD_CONTROL: return AimdNextSendTime(); case LEDBAT_CONTROL: return LedbatNextSendTime(); + case CLOSE_CONTROL: return TINT_NEVER; default: assert(false); } } @@ -54,6 +55,8 @@ tint Channel::SwitchSendControl (int control_mode) { break; case LEDBAT_CONTROL: break; + case CLOSE_CONTROL: + break; default: assert(false); } @@ -63,7 +66,7 @@ tint Channel::SwitchSendControl (int control_mode) { tint Channel::KeepAliveNextSendTime () { if (sent_since_recv_>=3 && last_recv_time_peer_channel_id_) { - delete this; - return; + peer_channel_id_ = 0; + Close(); + return; // this is a self-connection } } // FUTURE: channel forking @@ -537,8 +538,8 @@ void Channel::Loop (tint howlong) { Channel* sender(NULL); while (!sender && !send_queue.is_empty()) { // dequeue tintbin next = send_queue.pop(); - send_time = next.time; sender = channel((int)next.bin); + send_time = next.time; if (sender && sender->next_send_time_!=send_time && sender->next_send_time_!=TINT_NEVER ) sender = NULL; // it was a stale entry @@ -546,15 +547,10 @@ void Channel::Loop (tint howlong) { if ( sender!=NULL && send_time<=NOW ) { // it's time - if (sender->next_send_time_id(), - tintstr(send_time)); - sender->Send(); - sender->Reschedule(); - } else { // or close the channel - dprintf("%s #%u closed sendctrl\n",tintstr(),sender->id()); - delete sender; - } + dprintf("%s #%u sch_send %s\n",tintstr(),sender->id(), + tintstr(send_time)); + sender->Send(); + sender->Reschedule(); } else { // it's too early, wait @@ -576,12 +572,19 @@ void Channel::Loop (tint howlong) { } +void Channel::Close () { + this->SwitchSendControl(CLOSE_CONTROL); +} + + void Channel::Reschedule () { next_send_time_ = NextSendTime(); if (next_send_time_!=TINT_NEVER) { assert(next_send_time_