MCPcopy Create free account
hub / github.com/ReadyTalk/avian / Java_java_nio_channels_SocketChannel_natRead

Function Java_java_nio_channels_SocketChannel_natRead

classpath/java-nio.cpp:498–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498extern "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
541extern "C" JNIEXPORT jint JNICALL
542 Java_java_nio_channels_DatagramChannel_receive(JNIEnv* e,

Callers

nothing calls this directly

Calls 5

freeFunction · 0.85
eagainFunction · 0.85
throwIOExceptionFunction · 0.85
allocateFunction · 0.70
doReadFunction · 0.70

Tested by

no test coverage detected