mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
Reviewed-by: clanger, michaelm
This commit is contained in:
parent
aa5637f24e
commit
755872aa82
8 changed files with 52 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -740,8 +740,7 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
|||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_net_PlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) {
|
||||
|
||||
jint ret = -1;
|
||||
int count = 0;
|
||||
jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
|
||||
jint fd;
|
||||
|
||||
|
@ -752,8 +751,7 @@ Java_java_net_PlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) {
|
|||
} else {
|
||||
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
|
||||
}
|
||||
/* NET_SocketAvailable returns 0 for failure, 1 for success */
|
||||
if (NET_SocketAvailable(fd, &ret) == 0){
|
||||
if (NET_SocketAvailable(fd, &count) != 0) {
|
||||
if (errno == ECONNRESET) {
|
||||
JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
|
||||
} else {
|
||||
|
@ -761,7 +759,7 @@ Java_java_net_PlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) {
|
|||
(env, JNU_JAVANETPKG "SocketException", "ioctl FIONREAD failed");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return (jint) count;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -123,12 +123,10 @@ int getDefaultScopeID(JNIEnv *env) {
|
|||
} while((_result == -1) && (errno == EINTR)); \
|
||||
} while(0)
|
||||
|
||||
int NET_SocketAvailable(int s, jint *pbytes) {
|
||||
int NET_SocketAvailable(int s, int *pbytes) {
|
||||
int result;
|
||||
RESTARTABLE(ioctl(s, FIONREAD, pbytes), result);
|
||||
// note: ioctl can return 0 when successful, NET_SocketAvailable
|
||||
// is expected to return 0 on failure and 1 on success.
|
||||
return (result == -1) ? 0 : 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __solaris__
|
||||
|
|
|
@ -92,7 +92,6 @@ int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
|||
int NET_SocketClose(int s);
|
||||
int NET_Dup2(int oldfd, int newfd);
|
||||
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
|
||||
int NET_SocketAvailable(int s, jint *pbytes);
|
||||
|
||||
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
|
||||
const char* hostname,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -683,6 +683,17 @@ Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow)
|
|||
handleSocketError(env, errno);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_ch_Net_available(JNIEnv *env, jclass cl, jobject fdo)
|
||||
{
|
||||
int count = 0;
|
||||
if (NET_SocketAvailable(fdval(env, fdo), &count) != 0) {
|
||||
handleSocketError(env, errno);
|
||||
return IOS_THROWN;
|
||||
}
|
||||
return (jint) count;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlong timeout)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue