| 591 | } |
| 592 | |
| 593 | extern "C" JNIEXPORT jint JNICALL |
| 594 | Java_java_nio_channels_SocketChannel_natWrite(JNIEnv* e, |
| 595 | jclass, |
| 596 | jint socket, |
| 597 | jbyteArray buffer, |
| 598 | jint offset, |
| 599 | jint length, |
| 600 | jboolean blocking) |
| 601 | { |
| 602 | int r; |
| 603 | if (blocking) { |
| 604 | uint8_t* buf = static_cast<uint8_t*>(allocate(e, length)); |
| 605 | if (buf) { |
| 606 | e->GetByteArrayRegion( |
| 607 | buffer, offset, length, reinterpret_cast<jbyte*>(buf)); |
| 608 | r = ::doWrite(socket, buf, length); |
| 609 | free(buf); |
| 610 | } else { |
| 611 | return 0; |
| 612 | } |
| 613 | } else { |
| 614 | jboolean isCopy; |
| 615 | uint8_t* buf |
| 616 | = static_cast<uint8_t*>(e->GetPrimitiveArrayCritical(buffer, &isCopy)); |
| 617 | |
| 618 | r = ::doWrite(socket, buf + offset, length); |
| 619 | |
| 620 | e->ReleasePrimitiveArrayCritical(buffer, buf, 0); |
| 621 | } |
| 622 | |
| 623 | if (r < 0) { |
| 624 | if (eagain()) { |
| 625 | return 0; |
| 626 | } else { |
| 627 | throwIOException(e); |
| 628 | } |
| 629 | } |
| 630 | return r; |
| 631 | } |
| 632 | |
| 633 | extern "C" JNIEXPORT jint JNICALL |
| 634 | Java_java_nio_channels_DatagramChannel_write(JNIEnv* e, |
no test coverage detected