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:
Alan Bateman 2019-01-22 16:39:52 +00:00
parent aa5637f24e
commit 755872aa82
8 changed files with 52 additions and 17 deletions

View file

@ -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
@ -398,6 +398,17 @@ NET_GetSockOpt(int s, int level, int optname, void *optval,
return rv;
}
JNIEXPORT int JNICALL
NET_SocketAvailable(int s, int *pbytes) {
u_long arg;
if (ioctlsocket((SOCKET)s, FIONREAD, &arg) == SOCKET_ERROR) {
return -1;
} else {
*pbytes = (int) arg;
return 0;
}
}
/*
* Sets SO_ECLUSIVEADDRUSE if SO_REUSEADDR is not already set.
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2017, 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
@ -550,6 +550,17 @@ Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow) {
}
}
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, WSAGetLastError());
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)
{