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

Side by Side Diff: mojo/edk/system/data_pipe_producer_dispatcher.cc

Issue 2341633005: Mojo: Fix data pipe ALL_OR_NONE write capacity check. (Closed)
Patch Set: Created 4 years, 3 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/edk/system/data_pipe_producer_dispatcher.h" 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return MOJO_RESULT_BUSY; 130 return MOJO_RESULT_BUSY;
131 131
132 if (peer_closed_) 132 if (peer_closed_)
133 return MOJO_RESULT_FAILED_PRECONDITION; 133 return MOJO_RESULT_FAILED_PRECONDITION;
134 134
135 if (*num_bytes % options_.element_num_bytes != 0) 135 if (*num_bytes % options_.element_num_bytes != 0)
136 return MOJO_RESULT_INVALID_ARGUMENT; 136 return MOJO_RESULT_INVALID_ARGUMENT;
137 if (*num_bytes == 0) 137 if (*num_bytes == 0)
138 return MOJO_RESULT_OK; // Nothing to do. 138 return MOJO_RESULT_OK; // Nothing to do.
139 139
140 bool all_or_none = flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE; 140 if ((flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE) &&
141 uint32_t min_num_bytes_to_write = all_or_none ? *num_bytes : 0; 141 (*num_bytes > available_capacity_)) {
142 if (min_num_bytes_to_write > options_.capacity_num_bytes) {
143 // Don't return "should wait" since you can't wait for a specified amount of 142 // Don't return "should wait" since you can't wait for a specified amount of
144 // data. 143 // data.
145 return MOJO_RESULT_OUT_OF_RANGE; 144 return MOJO_RESULT_OUT_OF_RANGE;
miu 2016/09/14 22:40:23 Should this instead be: 1. MOJO_RESULT_SHOULD_WAI
jam 2016/09/15 17:08:34 the canonical documentation is in https://cs.chrom
146 } 145 }
147 146
148 DCHECK_LE(available_capacity_, options_.capacity_num_bytes); 147 DCHECK_LE(available_capacity_, options_.capacity_num_bytes);
149 uint32_t num_bytes_to_write = std::min(*num_bytes, available_capacity_); 148 uint32_t num_bytes_to_write = std::min(*num_bytes, available_capacity_);
150 if (num_bytes_to_write == 0) 149 if (num_bytes_to_write == 0)
151 return MOJO_RESULT_SHOULD_WAIT; 150 return MOJO_RESULT_SHOULD_WAIT;
152 151
153 HandleSignalsState old_state = GetHandleSignalsStateNoLock(); 152 HandleSignalsState old_state = GetHandleSignalsStateNoLock();
154 153
155 *num_bytes = num_bytes_to_write; 154 *num_bytes = num_bytes_to_write;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 540 }
542 541
543 if (peer_closed_ != was_peer_closed || 542 if (peer_closed_ != was_peer_closed ||
544 available_capacity_ != previous_capacity) { 543 available_capacity_ != previous_capacity) {
545 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); 544 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock());
546 } 545 }
547 } 546 }
548 547
549 } // namespace edk 548 } // namespace edk
550 } // namespace mojo 549 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/data_pipe_unittest.cc » ('j') | mojo/edk/system/data_pipe_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698