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

Side by Side Diff: Source/platform/network/SocketStreamHandle.cpp

Issue 311993006: [WebSocket] bufferedAmount should not decrease inside a task. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 bool SocketStreamHandle::send(const char* data, int length) 187 bool SocketStreamHandle::send(const char* data, int length)
188 { 188 {
189 if (m_state == Connecting || m_state == Closing) 189 if (m_state == Connecting || m_state == Closing)
190 return false; 190 return false;
191 if (!m_buffer.isEmpty()) { 191 if (!m_buffer.isEmpty()) {
192 if (m_buffer.size() + length > bufferSize) { 192 if (m_buffer.size() + length > bufferSize) {
193 // FIXME: report error to indicate that buffer has no more space. 193 // FIXME: report error to indicate that buffer has no more space.
194 return false; 194 return false;
195 } 195 }
196 m_buffer.append(data, length); 196 m_buffer.append(data, length);
197 if (m_client)
198 m_client->didUpdateBufferedAmount(this, bufferedAmount());
199 return true; 197 return true;
200 } 198 }
201 int bytesWritten = 0; 199 int bytesWritten = 0;
202 if (m_state == Open) 200 if (m_state == Open)
203 bytesWritten = sendInternal(data, length); 201 bytesWritten = sendInternal(data, length);
204 if (bytesWritten < 0) 202 if (bytesWritten < 0)
205 return false; 203 return false;
204 if (m_client)
205 m_client->didConsumeBufferedAmount(this, bytesWritten);
206 if (m_buffer.size() + length - bytesWritten > bufferSize) { 206 if (m_buffer.size() + length - bytesWritten > bufferSize) {
207 // FIXME: report error to indicate that buffer has no more space. 207 // FIXME: report error to indicate that buffer has no more space.
208 return false; 208 return false;
209 } 209 }
210 if (bytesWritten < length) { 210 if (bytesWritten < length) {
211 m_buffer.append(data + bytesWritten, length - bytesWritten); 211 m_buffer.append(data + bytesWritten, length - bytesWritten);
212 if (m_client)
213 m_client->didUpdateBufferedAmount(this, bufferedAmount());
214 } 212 }
215 return true; 213 return true;
216 } 214 }
217 215
218 void SocketStreamHandle::close() 216 void SocketStreamHandle::close()
219 { 217 {
220 if (m_state == Closed) 218 if (m_state == Closed)
221 return; 219 return;
222 m_state = Closing; 220 m_state = Closing;
223 if (!m_buffer.isEmpty()) 221 if (!m_buffer.isEmpty())
(...skipping 28 matching lines...) Expand all
252 } 250 }
253 } 251 }
254 bool pending; 252 bool pending;
255 do { 253 do {
256 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs tBlockSize()); 254 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs tBlockSize());
257 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize()); 255 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize());
258 if (bytesWritten <= 0) 256 if (bytesWritten <= 0)
259 return false; 257 return false;
260 ASSERT(m_buffer.size() - bytesWritten <= bufferSize); 258 ASSERT(m_buffer.size() - bytesWritten <= bufferSize);
261 m_buffer.consume(bytesWritten); 259 m_buffer.consume(bytesWritten);
260 if (m_client)
261 m_client->didConsumeBufferedAmount(this, bytesWritten);
262 } while (!pending && !m_buffer.isEmpty()); 262 } while (!pending && !m_buffer.isEmpty());
tyoshino (SeeGerritForStatus) 2014/06/19 07:38:54 ideally, didConsumeBufferedAmount should happen ou
yhirano 2014/06/19 07:49:43 Done.
263 if (m_client)
264 m_client->didUpdateBufferedAmount(this, bufferedAmount());
265 return true; 263 return true;
266 } 264 }
267 265
268 int SocketStreamHandle::sendInternal(const char* buf, int len) 266 int SocketStreamHandle::sendInternal(const char* buf, int len)
269 { 267 {
270 if (!m_internal) 268 if (!m_internal)
271 return 0; 269 return 0;
272 return m_internal->send(buf, len); 270 return m_internal->send(buf, len);
273 } 271 }
274 272
275 void SocketStreamHandle::closeInternal() 273 void SocketStreamHandle::closeInternal()
276 { 274 {
277 if (m_internal) 275 if (m_internal)
278 m_internal->close(); 276 m_internal->close();
279 } 277 }
280 278
281 } // namespace WebCore 279 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698