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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java

Issue 2697833003: [Cronet] Add isDone() check in CronetBidirectionalStream#onWritevCompleted (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.net.impl; 5 package org.chromium.net.impl;
6 6
7 import org.chromium.base.Log; 7 import org.chromium.base.Log;
8 import org.chromium.base.VisibleForTesting; 8 import org.chromium.base.VisibleForTesting;
9 import org.chromium.base.annotations.CalledByNative; 9 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.JNINamespace; 10 import org.chromium.base.annotations.JNINamespace;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 for (ByteBuffer buffer : mFlushData) { 407 for (ByteBuffer buffer : mFlushData) {
408 flushData.add(buffer.asReadOnlyBuffer()); 408 flushData.add(buffer.asReadOnlyBuffer());
409 } 409 }
410 return flushData; 410 return flushData;
411 } 411 }
412 } 412 }
413 413
414 @Override 414 @Override
415 public void cancel() { 415 public void cancel() {
416 synchronized (mNativeStreamLock) { 416 synchronized (mNativeStreamLock) {
417 if (isDoneLocked() || mReadState == State.NOT_STARTED) { 417 if (isDoneLocked()) {
418 return; 418 return;
419 } 419 }
420 mReadState = mWriteState = State.CANCELED; 420 mReadState = mWriteState = State.CANCELED;
421 destroyNativeStreamLocked(true); 421 destroyNativeStreamLocked(true);
422 } 422 }
423 } 423 }
424 424
425 @Override 425 @Override
426 public boolean isDone() { 426 public boolean isDone() {
427 synchronized (mNativeStreamLock) { 427 synchronized (mNativeStreamLock) {
428 return isDoneLocked(); 428 return isDoneLocked();
429 } 429 }
430 } 430 }
431 431
432 @GuardedBy("mNativeStreamLock") 432 @GuardedBy("mNativeStreamLock")
433 private boolean isDoneLocked() { 433 private boolean isDoneLocked() {
434 return mReadState != State.NOT_STARTED && mNativeStream == 0; 434 return mNativeStream == 0;
435 } 435 }
436 436
437 /* 437 /*
438 * Runs an onSucceeded callback if both Read and Write sides are closed. 438 * Runs an onSucceeded callback if both Read and Write sides are closed.
439 */ 439 */
440 private void maybeOnSucceededOnExecutor() { 440 private void maybeOnSucceededOnExecutor() {
441 synchronized (mNativeStreamLock) { 441 synchronized (mNativeStreamLock) {
442 if (isDoneLocked()) { 442 if (isDoneLocked()) {
443 return; 443 return;
444 } 444 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 postTaskToExecutor(mOnReadCompletedTask); 539 postTaskToExecutor(mOnReadCompletedTask);
540 } 540 }
541 541
542 @SuppressWarnings("unused") 542 @SuppressWarnings("unused")
543 @CalledByNative 543 @CalledByNative
544 private void onWritevCompleted(final ByteBuffer[] byteBuffers, int[] initial Positions, 544 private void onWritevCompleted(final ByteBuffer[] byteBuffers, int[] initial Positions,
545 int[] initialLimits, boolean endOfStream) { 545 int[] initialLimits, boolean endOfStream) {
546 assert byteBuffers.length == initialPositions.length; 546 assert byteBuffers.length == initialPositions.length;
547 assert byteBuffers.length == initialLimits.length; 547 assert byteBuffers.length == initialLimits.length;
548 synchronized (mNativeStreamLock) { 548 synchronized (mNativeStreamLock) {
549 mWriteState = State.WAITING_FOR_FLUSH; 549 mWriteState = State.WAITING_FOR_FLUSH;
mef 2017/02/14 16:27:24 I think we should add the check
550 // Flush if there is anything in the flush queue mFlushData. 550 // Flush if there is anything in the flush queue mFlushData.
551 if (!mFlushData.isEmpty()) { 551 if (!mFlushData.isEmpty()) {
552 sendFlushDataLocked(); 552 sendFlushDataLocked();
553 } 553 }
554 } 554 }
555 for (int i = 0; i < byteBuffers.length; i++) { 555 for (int i = 0; i < byteBuffers.length; i++) {
556 ByteBuffer buffer = byteBuffers[i]; 556 ByteBuffer buffer = byteBuffers[i];
557 if (buffer.position() != initialPositions[i] || buffer.limit() != in itialLimits[i]) { 557 if (buffer.position() != initialPositions[i] || buffer.limit() != in itialLimits[i]) {
558 failWithException(new CronetExceptionImpl( 558 failWithException(new CronetExceptionImpl(
559 "ByteBuffer modified externally during write", null)); 559 "ByteBuffer modified externally during write", null));
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 private native boolean nativeReadData( 803 private native boolean nativeReadData(
804 long nativePtr, ByteBuffer byteBuffer, int position, int limit); 804 long nativePtr, ByteBuffer byteBuffer, int position, int limit);
805 805
806 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") 806 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter")
807 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions, 807 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions,
808 int[] limits, boolean endOfStream); 808 int[] limits, boolean endOfStream);
809 809
810 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") 810 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter")
811 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); 811 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled);
812 } 812 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698