tianshuang opened a new pull request, #562: URL: https://github.com/apache/tomcat/pull/562
The following are the low-level implementations of the Solaris platform, other platforms are similar: [Java_sun_nio_ch_DatagramDispatcher_write0](https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/solaris/native/sun/nio/ch/DatagramDispatcher.c#L82-L94): ```c JNIEXPORT jint JNICALL Java_sun_nio_ch_DatagramDispatcher_write0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); void *buf = (void *)jlong_to_ptr(address); int result = send(fd, buf, len, 0); if (result < 0 && errno == ECONNREFUSED) { JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); return -2; } return convertReturnVal(env, result, JNI_FALSE); } ``` [Java_sun_nio_ch_FileDispatcherImpl_write0](https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c#L100-L108): ```c JNIEXPORT jint JNICALL Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); void *buf = (void *)jlong_to_ptr(address); return convertReturnVal(env, write(fd, buf, len), JNI_FALSE); } ``` [convertReturnVal](https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/solaris/native/sun/nio/ch/IOUtil.c#L149-L172): ```c /* Declared in nio_util.h for use elsewhere in NIO */ jint convertReturnVal(JNIEnv *env, jint n, jboolean reading) { if (n > 0) /* Number of bytes written */ return n; else if (n == 0) { if (reading) { return IOS_EOF; /* EOF is -1 in javaland */ } else { return 0; } } else if (errno == EAGAIN) return IOS_UNAVAILABLE; else if (errno == EINTR) return IOS_INTERRUPTED; else { const char *msg = reading ? "Read failed" : "Write failed"; JNU_ThrowIOExceptionWithLastError(env, msg); return IOS_THROWN; } } ``` In fact, it is only possible to return -1 when `read` is called, indicating that the end of the channel stream has been reached. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org