change rpc_ping to return the status code

This commit is contained in:
Doug MacEachern 2006-02-27 01:33:12 +00:00
parent 8342b063de
commit f0cdd946c5
4 changed files with 28 additions and 27 deletions

View File

@ -410,7 +410,7 @@ JNIEXPORT jobjectArray SIGAR_JNI(Sigar_getFileSystemListNative)
return fsarray;
}
JNIEXPORT jboolean SIGAR_JNI(RPC_ping)
JNIEXPORT jint SIGAR_JNI(RPC_ping)
(JNIEnv *env, jclass cls_obj, jstring jhostname,
jint protocol, jlong program, jlong version)
{
@ -419,23 +419,23 @@ JNIEXPORT jboolean SIGAR_JNI(RPC_ping)
#else
jboolean is_copy;
const char *hostname;
jboolean retval;
int status;
if (!jhostname) {
return JNI_FALSE;
return 13; /* RPC_UNKNOWNHOST */
}
hostname = JENV->GetStringUTFChars(env, jhostname, &is_copy);
retval =
(sigar_rpc_ping((char *)hostname,
protocol, program, version) == SIGAR_OK);
status =
sigar_rpc_ping((char *)hostname,
protocol, program, version);
if (is_copy) {
JENV->ReleaseStringUTFChars(env, jhostname, hostname);
}
return retval;
return status;
#endif
}

View File

@ -30,7 +30,7 @@ public class NfsFileSystem extends FileSystem {
}
public boolean ping() {
return RPC.ping(getHostname(), NFS_PROGRAM);
return RPC.ping(getHostname(), NFS_PROGRAM) == 0;
}
public String getUnreachableMessage() {

View File

@ -11,26 +11,26 @@ public class RPC {
public static final int UDP = NetFlags.CONN_UDP;
public static final int TCP = NetFlags.CONN_TCP;
public static native boolean ping(String hostname,
int protocol,
long program,
long version);
public static native int ping(String hostname,
int protocol,
long program,
long version);
public static boolean ping(String hostname,
int protocol,
String program,
long version) {
public static int ping(String hostname,
int protocol,
String program,
long version) {
return ping(hostname,
protocol,
getProgram(program),
version);
}
public static boolean ping(String hostname, long program) {
public static int ping(String hostname, long program) {
return ping(hostname, UDP, program, 2);
}
public static boolean ping(String hostname, String program) {
public static int ping(String hostname, String program) {
return ping(hostname, UDP, program, 2);
}

View File

@ -493,7 +493,7 @@ int sigar_cpu_mhz_from_model(char *model)
#include <sys/socket.h>
#endif
static int get_sockaddr(struct sockaddr_in *addr, char *host)
static enum clnt_stat get_sockaddr(struct sockaddr_in *addr, char *host)
{
register struct hostent *hp;
@ -502,12 +502,12 @@ static int get_sockaddr(struct sockaddr_in *addr, char *host)
if ((addr->sin_addr.s_addr = inet_addr(host)) == -1) {
if (!(hp = sigar_gethostbyname(host))) {
return -1;
return RPC_UNKNOWNHOST;
}
memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
}
return SIGAR_OK;
return RPC_SUCCESS;
}
SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
@ -517,13 +517,14 @@ SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
{
CLIENT *client;
struct sockaddr_in addr;
int sock, retval=SIGAR_OK;
int sock;
struct timeval timeout, interval;
unsigned short port = 0;
enum clnt_stat rpc_stat;
if (get_sockaddr(&addr, host) != SIGAR_OK) {
return -1;
rpc_stat = get_sockaddr(&addr, host);
if (rpc_stat != RPC_SUCCESS) {
return rpc_stat;
}
interval.tv_sec = 2;
@ -533,7 +534,7 @@ SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
client = clntudp_create(&addr, program, version,
interval, &sock);
if (!client) {
return -1;
return RPC_FAILED;
}
timeout.tv_sec = 10;
@ -542,12 +543,12 @@ SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
(xdrproc_t)xdr_void, NULL, timeout);
if (rpc_stat != RPC_SUCCESS) {
retval = -1;
return rpc_stat;
}
clnt_destroy(client);
return retval;
return RPC_SUCCESS;
}
#endif