OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/flip/flip_session.h" | 5 #include "net/flip/flip_session.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if (result >= 0) { | 454 if (result >= 0) { |
455 // TODO(mbelshe) Verify that we wrote ALL the bytes of the frame. | 455 // TODO(mbelshe) Verify that we wrote ALL the bytes of the frame. |
456 // The code current is broken in the case of a partial write. | 456 // The code current is broken in the case of a partial write. |
457 DCHECK_EQ(static_cast<size_t>(result), in_flight_write_.size()); | 457 DCHECK_EQ(static_cast<size_t>(result), in_flight_write_.size()); |
458 | 458 |
459 // We only notify the stream when we've fully written the pending flip | 459 // We only notify the stream when we've fully written the pending flip |
460 // frame. | 460 // frame. |
461 scoped_refptr<FlipStream> stream = in_flight_write_.stream(); | 461 scoped_refptr<FlipStream> stream = in_flight_write_.stream(); |
462 DCHECK(stream.get()); | 462 DCHECK(stream.get()); |
463 | 463 |
464 if (!stream->cancelled()) { | 464 // Report the number of bytes written to the caller, but exclude the |
465 // Report the number of bytes written to the caller, but exclude the | 465 // frame size overhead. |
466 // frame size overhead. | 466 if (result > 0) { |
467 if (result > 0) { | 467 // TODO(willchan): This is an unsafe DCHECK. I'm hitting this. We should |
468 DCHECK(result > static_cast<int>(flip::FlipFrame::size())); | 468 // handle small writes appropriately. |
469 result -= static_cast<int>(flip::FlipFrame::size()); | 469 DCHECK(result > static_cast<int>(flip::FlipFrame::size())); |
470 } | 470 result -= static_cast<int>(flip::FlipFrame::size()); |
471 stream->OnWriteComplete(result); | |
472 } | 471 } |
| 472 stream->OnWriteComplete(result); |
473 | 473 |
474 // Cleanup the write which just completed. | 474 // Cleanup the write which just completed. |
475 in_flight_write_.release(); | 475 in_flight_write_.release(); |
476 | 476 |
477 // Write more data. We're already in a continuation, so we can | 477 // Write more data. We're already in a continuation, so we can |
478 // go ahead and write it immediately (without going back to the | 478 // go ahead and write it immediately (without going back to the |
479 // message loop). | 479 // message loop). |
480 WriteSocketLater(); | 480 WriteSocketLater(); |
481 } else { | 481 } else { |
482 // TODO(mbelshe): Deal with result < 0 error case. | 482 // TODO(mbelshe): Deal with result < 0 error case. |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 LOG(ERROR) << "Flip stream closed: " << frame->status(); | 853 LOG(ERROR) << "Flip stream closed: " << frame->status(); |
854 // TODO(mbelshe): Map from Flip-protocol errors to something sensical. | 854 // TODO(mbelshe): Map from Flip-protocol errors to something sensical. |
855 // For now, it doesn't matter much - it is a protocol error. | 855 // For now, it doesn't matter much - it is a protocol error. |
856 stream->OnClose(ERR_FAILED); | 856 stream->OnClose(ERR_FAILED); |
857 } | 857 } |
858 | 858 |
859 DeactivateStream(stream_id); | 859 DeactivateStream(stream_id); |
860 } | 860 } |
861 | 861 |
862 } // namespace net | 862 } // namespace net |
OLD | NEW |