summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 21:52:57 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 21:52:57 +0000
commite221eeb710a2b463402d4550688bb9e0d9cdd496 (patch)
tree852e8776b7bf950f61c6b7f031bb2206b6f7e501 /remoting/protocol
parent6b7d1aab099945e69cd259c17fa75d926638ff33 (diff)
downloadchromium_src-e221eeb710a2b463402d4550688bb9e0d9cdd496.zip
chromium_src-e221eeb710a2b463402d4550688bb9e0d9cdd496.tar.gz
chromium_src-e221eeb710a2b463402d4550688bb9e0d9cdd496.tar.bz2
Handle error in BufferedStreamWriter and friends
Sets the closed flag to true when an error is encountered in the socket. BUG=None TEST=None Review URL: http://codereview.chromium.org/4705002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65859 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r--remoting/protocol/buffered_socket_writer.cc21
-rw-r--r--remoting/protocol/buffered_socket_writer.h10
2 files changed, 29 insertions, 2 deletions
diff --git a/remoting/protocol/buffered_socket_writer.cc b/remoting/protocol/buffered_socket_writer.cc
index 1931cd5..bbb0324 100644
--- a/remoting/protocol/buffered_socket_writer.cc
+++ b/remoting/protocol/buffered_socket_writer.cc
@@ -77,10 +77,10 @@ void BufferedSocketWriterBase::DoWrite() {
if (result == net::ERR_IO_PENDING) {
write_pending_ = true;
} else {
+ HandleError(result);
if (write_failed_callback_.get())
write_failed_callback_->Run(result);
}
-
return;
}
}
@@ -91,6 +91,7 @@ void BufferedSocketWriterBase::OnWritten(int result) {
write_pending_ = false;
if (result < 0) {
+ HandleError(result);
if (write_failed_callback_.get())
write_failed_callback_->Run(result);
return;
@@ -106,6 +107,17 @@ void BufferedSocketWriterBase::OnWritten(int result) {
FROM_HERE, NewRunnableMethod(this, &BufferedSocketWriterBase::DoWrite));
}
+void BufferedSocketWriterBase::HandleError(int result) {
+ AutoLock auto_lock(lock_);
+ closed_ = true;
+ while (!queue_.empty()) {
+ queue_.pop();
+ }
+
+ // Notify subclass that an error is received.
+ OnError_Locked(result);
+}
+
int BufferedSocketWriterBase::GetBufferSize() {
AutoLock auto_lock(lock_);
return buffer_size_;
@@ -145,6 +157,10 @@ void BufferedSocketWriter::AdvanceBufferPosition_Locked(int written) {
current_buf_->DidConsume(written);
}
+void BufferedSocketWriter::OnError_Locked(int result) {
+ current_buf_ = NULL;
+}
+
BufferedDatagramWriter::BufferedDatagramWriter() { }
BufferedDatagramWriter::~BufferedDatagramWriter() { }
@@ -164,6 +180,9 @@ void BufferedDatagramWriter::AdvanceBufferPosition_Locked(int written) {
queue_.pop();
}
+void BufferedDatagramWriter::OnError_Locked(int result) {
+ // Nothing to do here.
+}
} // namespace protocol
} // namespace remoting
diff --git a/remoting/protocol/buffered_socket_writer.h b/remoting/protocol/buffered_socket_writer.h
index 04e41b6..c786c44 100644
--- a/remoting/protocol/buffered_socket_writer.h
+++ b/remoting/protocol/buffered_socket_writer.h
@@ -63,16 +63,22 @@ class BufferedSocketWriterBase
DataQueue queue_;
int buffer_size_;
- // Following two methods must be implemented in child classes.
+ // Following three methods must be implemented in child classes.
// GetNextPacket() returns next packet that needs to be written to the
// socket. |buffer| must be set to NULL if there is nothing left in the queue.
virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size) = 0;
virtual void AdvanceBufferPosition_Locked(int written) = 0;
+ // This method is called whenever there is an error writing to the socket.
+ virtual void OnError_Locked(int result) = 0;
+
private:
void DoWrite();
void OnWritten(int result);
+ // This method is called when an error is encountered.
+ void HandleError(int result);
+
// Must be locked when accessing |socket_|, |queue_| and |buffer_size_|;
Lock lock_;
@@ -95,6 +101,7 @@ class BufferedSocketWriter : public BufferedSocketWriterBase {
protected:
virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size);
virtual void AdvanceBufferPosition_Locked(int written);
+ virtual void OnError_Locked(int result);
private:
scoped_refptr<net::DrainableIOBuffer> current_buf_;
@@ -108,6 +115,7 @@ class BufferedDatagramWriter : public BufferedSocketWriterBase {
protected:
virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size);
virtual void AdvanceBufferPosition_Locked(int written);
+ virtual void OnError_Locked(int result);
};
} // namespace protocol