diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2011-04-04 11:03:03 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-04-04 11:03:03 -0700 |
commit | 27e00544ea08d25e8e9b1b94264205f9d53030fb (patch) | |
tree | 67f0666dce75aacb210db8c93402662f90a0f5d5 /core | |
parent | 9b1b64399502af0a08beac3014f2294644753602 (diff) | |
parent | 9907d161584415c81de1099678f160da172fd1a6 (diff) | |
download | frameworks_base-27e00544ea08d25e8e9b1b94264205f9d53030fb.zip frameworks_base-27e00544ea08d25e8e9b1b94264205f9d53030fb.tar.gz frameworks_base-27e00544ea08d25e8e9b1b94264205f9d53030fb.tar.bz2 |
am 9907d161: Merge "Fix data corruption when writing to Bluetooth socket"
* commit '9907d161584415c81de1099678f160da172fd1a6':
Fix data corruption when writing to Bluetooth socket
Diffstat (limited to 'core')
-rw-r--r-- | core/jni/android_bluetooth_BluetoothSocket.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/core/jni/android_bluetooth_BluetoothSocket.cpp b/core/jni/android_bluetooth_BluetoothSocket.cpp index 31ebf8c..a62537d 100644 --- a/core/jni/android_bluetooth_BluetoothSocket.cpp +++ b/core/jni/android_bluetooth_BluetoothSocket.cpp @@ -448,7 +448,7 @@ static jint writeNative(JNIEnv *env, jobject obj, jbyteArray jb, jint offset, #ifdef HAVE_BLUETOOTH LOGV(__FUNCTION__); - int ret; + int ret, total; jbyte *b; int sz; struct asocket *s = get_socketData(env, obj); @@ -471,15 +471,21 @@ static jint writeNative(JNIEnv *env, jobject obj, jbyteArray jb, jint offset, return -1; } - ret = asocket_write(s, &b[offset], length, -1); - if (ret < 0) { - jniThrowIOException(env, errno); - env->ReleaseByteArrayElements(jb, b, JNI_ABORT); - return -1; + total = 0; + while (length > 0) { + ret = asocket_write(s, &b[offset], length, -1); + if (ret < 0) { + jniThrowIOException(env, errno); + env->ReleaseByteArrayElements(jb, b, JNI_ABORT); + return -1; + } + offset += ret; + total += ret; + length -= ret; } env->ReleaseByteArrayElements(jb, b, JNI_ABORT); // no need to commit - return (jint)ret; + return (jint)total; #endif jniThrowIOException(env, ENOSYS); |