diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 03:11:47 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 03:11:47 +0000 |
commit | ba1161fab422b5a0d35c715c6082e1a4c412e44d (patch) | |
tree | 0000488cfd994888d9c0300317323a918a622774 /net/socket_stream/socket_stream.cc | |
parent | e1791eb5f5b9043c8bad12509deb7db687073755 (diff) | |
download | chromium_src-ba1161fab422b5a0d35c715c6082e1a4c412e44d.zip chromium_src-ba1161fab422b5a0d35c715c6082e1a4c412e44d.tar.gz chromium_src-ba1161fab422b5a0d35c715c6082e1a4c412e44d.tar.bz2 |
SocketStream::Close() disconnect the socket after all pending data sent.
SocketStream::Close() immediately disconnected the socket even if
it has some data to be sent. It is not desired behavior.
Change to that Close() just requests to close the socket, and when
all pending data have been processed, close the socket.
BUG=none
TEST=net_unittests passes
Review URL: http://codereview.chromium.org/2066011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream/socket_stream.cc')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index b2f7a2c..7c1369c 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -59,6 +59,7 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) current_write_buf_(NULL), write_buf_offset_(0), write_buf_size_(0), + closing_(false), metrics_(new SocketStreamMetrics(url)) { DCHECK(MessageLoop::current()) << "The current MessageLoop must exist"; @@ -175,9 +176,7 @@ void SocketStream::Close() { // of AddRef() and Release() in Connect() and Finish(), respectively. if (next_state_ == STATE_NONE) return; - if (socket_.get() && socket_->IsConnected()) - socket_->Disconnect(); - next_state_ = STATE_CLOSE; + closing_ = true; // Close asynchronously, so that delegate won't be called // back before returning Close(). MessageLoop::current()->PostTask( @@ -215,6 +214,8 @@ void SocketStream::DetachDelegate() { return; delegate_ = NULL; net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); + // We don't need to send pending data when client detach the delegate. + pending_write_bufs_.clear(); Close(); } @@ -809,6 +810,15 @@ int SocketStream::DoReadWrite(int result) { return ERR_CONNECTION_CLOSED; } + // If client has requested close(), and there's nothing to write, then + // let's close the socket. + // We don't care about receiving data after the socket is closed. + if (closing_ && !write_buf_ && pending_write_bufs_.empty()) { + socket_->Disconnect(); + next_state_ = STATE_CLOSE; + return OK; + } + next_state_ = STATE_READ_WRITE; if (!read_buf_) { |