Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: remoting/protocol/socket_reader_base.cc

Issue 6277003: Simplified MessageReader and MessageDecoder classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/socket_reader_base.h ('k') | remoting/protocol/video_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/protocol/socket_reader_base.h" 5 #include "remoting/protocol/socket_reader_base.h"
6 6
7 #include "net/base/completion_callback.h" 7 #include "net/base/completion_callback.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/socket/socket.h" 10 #include "net/socket/socket.h"
11 11
12 namespace remoting { 12 namespace remoting {
13 13
14 namespace { 14 namespace {
15 int kReadBufferSize = 4096; 15 int kReadBufferSize = 4096;
16 } // namespace 16 } // namespace
17 17
18 SocketReaderBase::SocketReaderBase() 18 SocketReaderBase::SocketReaderBase()
19 : socket_(NULL), 19 : socket_(NULL),
20 closed_(false), 20 closed_(false),
21 ALLOW_THIS_IN_INITIALIZER_LIST( 21 ALLOW_THIS_IN_INITIALIZER_LIST(
22 read_callback_(this, &SocketReaderBase::OnRead)) { 22 read_callback_(this, &SocketReaderBase::OnRead)) {
23 } 23 }
24 24
25 SocketReaderBase::~SocketReaderBase() { } 25 SocketReaderBase::~SocketReaderBase() { }
26 26
27 void SocketReaderBase::Close() {
28 closed_ = true;
29 }
30
31 void SocketReaderBase::Init(net::Socket* socket) { 27 void SocketReaderBase::Init(net::Socket* socket) {
32 DCHECK(socket); 28 DCHECK(socket);
33 socket_ = socket; 29 socket_ = socket;
34 DoRead(); 30 DoRead();
35 } 31 }
36 32
37 void SocketReaderBase::DoRead() { 33 void SocketReaderBase::DoRead() {
38 while (true) { 34 while (true) {
39 read_buffer_ = new net::IOBuffer(kReadBufferSize); 35 read_buffer_ = new net::IOBuffer(kReadBufferSize);
40 int result = socket_->Read( 36 int result = socket_->Read(
41 read_buffer_, kReadBufferSize, &read_callback_); 37 read_buffer_, kReadBufferSize, &read_callback_);
42 HandleReadResult(result); 38 HandleReadResult(result);
43 if (result < 0) 39 if (result < 0)
44 break; 40 break;
45 } 41 }
46 } 42 }
47 43
48 void SocketReaderBase::OnRead(int result) { 44 void SocketReaderBase::OnRead(int result) {
49 if (!closed_) { 45 if (!closed_) {
50 HandleReadResult(result); 46 HandleReadResult(result);
51 DoRead(); 47 DoRead();
52 } 48 }
53 } 49 }
54 50
55 void SocketReaderBase::HandleReadResult(int result) { 51 void SocketReaderBase::HandleReadResult(int result) {
56 if (result > 0) { 52 if (result > 0) {
57 OnDataReceived(read_buffer_, result); 53 OnDataReceived(read_buffer_, result);
58 } else { 54 } else {
59 if (result != net::ERR_IO_PENDING) 55 if (result == net::ERR_CONNECTION_CLOSED) {
56 closed_ = true;
57 } else if (result != net::ERR_IO_PENDING) {
60 LOG(ERROR) << "Read() returned error " << result; 58 LOG(ERROR) << "Read() returned error " << result;
59 }
61 } 60 }
62 } 61 }
63 62
64 } // namespace remoting 63 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/socket_reader_base.h ('k') | remoting/protocol/video_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698