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

View File

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

View File

@ -11,12 +11,12 @@ public class RPC {
public static final int UDP = NetFlags.CONN_UDP; public static final int UDP = NetFlags.CONN_UDP;
public static final int TCP = NetFlags.CONN_TCP; public static final int TCP = NetFlags.CONN_TCP;
public static native boolean ping(String hostname, public static native int ping(String hostname,
int protocol, int protocol,
long program, long program,
long version); long version);
public static boolean ping(String hostname, public static int ping(String hostname,
int protocol, int protocol,
String program, String program,
long version) { long version) {
@ -26,11 +26,11 @@ public class RPC {
version); version);
} }
public static boolean ping(String hostname, long program) { public static int ping(String hostname, long program) {
return ping(hostname, UDP, program, 2); 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); return ping(hostname, UDP, program, 2);
} }

View File

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