| 496 | } |
| 497 | |
| 498 | extern "C" JNIEXPORT jint JNICALL |
| 499 | Java_java_nio_channels_SocketChannel_natRead(JNIEnv* e, |
| 500 | jclass, |
| 501 | jint socket, |
| 502 | jbyteArray buffer, |
| 503 | jint offset, |
| 504 | jint length, |
| 505 | jboolean blocking) |
| 506 | { |
| 507 | int r; |
| 508 | if (blocking) { |
| 509 | uint8_t* buf = static_cast<uint8_t*>(allocate(e, length)); |
| 510 | if (buf) { |
| 511 | r = ::doRead(socket, buf, length); |
| 512 | if (r > 0) { |
| 513 | e->SetByteArrayRegion(buffer, offset, r, reinterpret_cast<jbyte*>(buf)); |
| 514 | } |
| 515 | free(buf); |
| 516 | } else { |
| 517 | return 0; |
| 518 | } |
| 519 | } else { |
| 520 | jboolean isCopy; |
| 521 | uint8_t* buf |
| 522 | = static_cast<uint8_t*>(e->GetPrimitiveArrayCritical(buffer, &isCopy)); |
| 523 | |
| 524 | r = ::doRead(socket, buf + offset, length); |
| 525 | |
| 526 | e->ReleasePrimitiveArrayCritical(buffer, buf, 0); |
| 527 | } |
| 528 | |
| 529 | if (r < 0) { |
| 530 | if (eagain()) { |
| 531 | return 0; |
| 532 | } else { |
| 533 | throwIOException(e); |
| 534 | } |
| 535 | } else if (r == 0) { |
| 536 | return -1; |
| 537 | } |
| 538 | return r; |
| 539 | } |
| 540 | |
| 541 | extern "C" JNIEXPORT jint JNICALL |
| 542 | Java_java_nio_channels_DatagramChannel_receive(JNIEnv* e, |
nothing calls this directly
no test coverage detected