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

Side by Side Diff: webrtc/base/socketstream.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 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
« no previous file with comments | « webrtc/base/socketpool.cc ('k') | webrtc/base/sslidentity.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/socketstream.h" 11 #include "webrtc/base/socketstream.h"
12 12
13 #include "webrtc/base/checks.h"
14
13 namespace rtc { 15 namespace rtc {
14 16
15 SocketStream::SocketStream(AsyncSocket* socket) : socket_(NULL) { 17 SocketStream::SocketStream(AsyncSocket* socket) : socket_(NULL) {
16 Attach(socket); 18 Attach(socket);
17 } 19 }
18 20
19 SocketStream::~SocketStream() { 21 SocketStream::~SocketStream() {
20 delete socket_; 22 delete socket_;
21 } 23 }
22 24
(...skipping 15 matching lines...) Expand all
38 socket_->SignalConnectEvent.disconnect(this); 40 socket_->SignalConnectEvent.disconnect(this);
39 socket_->SignalReadEvent.disconnect(this); 41 socket_->SignalReadEvent.disconnect(this);
40 socket_->SignalWriteEvent.disconnect(this); 42 socket_->SignalWriteEvent.disconnect(this);
41 socket_->SignalCloseEvent.disconnect(this); 43 socket_->SignalCloseEvent.disconnect(this);
42 socket_ = NULL; 44 socket_ = NULL;
43 } 45 }
44 return socket; 46 return socket;
45 } 47 }
46 48
47 StreamState SocketStream::GetState() const { 49 StreamState SocketStream::GetState() const {
48 ASSERT(socket_ != NULL); 50 RTC_DCHECK(socket_ != NULL);
49 switch (socket_->GetState()) { 51 switch (socket_->GetState()) {
50 case Socket::CS_CONNECTED: 52 case Socket::CS_CONNECTED:
51 return SS_OPEN; 53 return SS_OPEN;
52 case Socket::CS_CONNECTING: 54 case Socket::CS_CONNECTING:
53 return SS_OPENING; 55 return SS_OPENING;
54 case Socket::CS_CLOSED: 56 case Socket::CS_CLOSED:
55 default: 57 default:
56 return SS_CLOSED; 58 return SS_CLOSED;
57 } 59 }
58 } 60 }
59 61
60 StreamResult SocketStream::Read(void* buffer, size_t buffer_len, 62 StreamResult SocketStream::Read(void* buffer, size_t buffer_len,
61 size_t* read, int* error) { 63 size_t* read, int* error) {
62 ASSERT(socket_ != NULL); 64 RTC_DCHECK(socket_ != NULL);
63 int result = socket_->Recv(buffer, buffer_len, nullptr); 65 int result = socket_->Recv(buffer, buffer_len, nullptr);
64 if (result < 0) { 66 if (result < 0) {
65 if (socket_->IsBlocking()) 67 if (socket_->IsBlocking())
66 return SR_BLOCK; 68 return SR_BLOCK;
67 if (error) 69 if (error)
68 *error = socket_->GetError(); 70 *error = socket_->GetError();
69 return SR_ERROR; 71 return SR_ERROR;
70 } 72 }
71 if ((result > 0) || (buffer_len == 0)) { 73 if ((result > 0) || (buffer_len == 0)) {
72 if (read) 74 if (read)
73 *read = result; 75 *read = result;
74 return SR_SUCCESS; 76 return SR_SUCCESS;
75 } 77 }
76 return SR_EOS; 78 return SR_EOS;
77 } 79 }
78 80
79 StreamResult SocketStream::Write(const void* data, size_t data_len, 81 StreamResult SocketStream::Write(const void* data, size_t data_len,
80 size_t* written, int* error) { 82 size_t* written, int* error) {
81 ASSERT(socket_ != NULL); 83 RTC_DCHECK(socket_ != NULL);
82 int result = socket_->Send(data, data_len); 84 int result = socket_->Send(data, data_len);
83 if (result < 0) { 85 if (result < 0) {
84 if (socket_->IsBlocking()) 86 if (socket_->IsBlocking())
85 return SR_BLOCK; 87 return SR_BLOCK;
86 if (error) 88 if (error)
87 *error = socket_->GetError(); 89 *error = socket_->GetError();
88 return SR_ERROR; 90 return SR_ERROR;
89 } 91 }
90 if (written) 92 if (written)
91 *written = result; 93 *written = result;
92 return SR_SUCCESS; 94 return SR_SUCCESS;
93 } 95 }
94 96
95 void SocketStream::Close() { 97 void SocketStream::Close() {
96 ASSERT(socket_ != NULL); 98 RTC_DCHECK(socket_ != NULL);
97 socket_->Close(); 99 socket_->Close();
98 } 100 }
99 101
100 void SocketStream::OnConnectEvent(AsyncSocket* socket) { 102 void SocketStream::OnConnectEvent(AsyncSocket* socket) {
101 ASSERT(socket == socket_); 103 RTC_DCHECK(socket == socket_);
102 SignalEvent(this, SE_OPEN | SE_READ | SE_WRITE, 0); 104 SignalEvent(this, SE_OPEN | SE_READ | SE_WRITE, 0);
103 } 105 }
104 106
105 void SocketStream::OnReadEvent(AsyncSocket* socket) { 107 void SocketStream::OnReadEvent(AsyncSocket* socket) {
106 ASSERT(socket == socket_); 108 RTC_DCHECK(socket == socket_);
107 SignalEvent(this, SE_READ, 0); 109 SignalEvent(this, SE_READ, 0);
108 } 110 }
109 111
110 void SocketStream::OnWriteEvent(AsyncSocket* socket) { 112 void SocketStream::OnWriteEvent(AsyncSocket* socket) {
111 ASSERT(socket == socket_); 113 RTC_DCHECK(socket == socket_);
112 SignalEvent(this, SE_WRITE, 0); 114 SignalEvent(this, SE_WRITE, 0);
113 } 115 }
114 116
115 void SocketStream::OnCloseEvent(AsyncSocket* socket, int err) { 117 void SocketStream::OnCloseEvent(AsyncSocket* socket, int err) {
116 ASSERT(socket == socket_); 118 RTC_DCHECK(socket == socket_);
117 SignalEvent(this, SE_CLOSE, err); 119 SignalEvent(this, SE_CLOSE, err);
118 } 120 }
119 121
120 122
121 } // namespace rtc 123 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/socketpool.cc ('k') | webrtc/base/sslidentity.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698