[netperf-dev] netperf4 commit notice r78 - trunk/src
raj at netperf.org
raj at netperf.org
Tue Mar 7 17:31:11 PST 2006
Author: raj
Date: 2006-03-07 17:31:09 -0800 (Tue, 07 Mar 2006)
New Revision: 78
Modified:
trunk/src/netlib.c
trunk/src/netlib.h
trunk/src/netperf.h
trunk/src/netsysstats_common.c
Log:
Many more steps towards Windows. Not sure if we've covered one of the
thousands of miles or not :)
Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c 2006-03-07 21:28:56 UTC (rev 77)
+++ trunk/src/netlib.c 2006-03-08 01:31:09 UTC (rev 78)
@@ -36,6 +36,10 @@
#include "config.h"
#endif
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -96,9 +100,8 @@
#endif
#ifdef WITH_GLIB
-# ifdef HAVE_GLIB_H
-# include <glib.h>
-# endif
+# include <glib.h>
+# include <gmodule.h>
#else
# ifdef HAVE_PTHREAD_H
# include <pthread.h>
@@ -138,6 +141,10 @@
#include "nettest_bsd.h"
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+
/* given a filename, return the first path to the file that stats
successfully - which is either the name already given, or that name
with NETPERFDIR prepended. */
@@ -149,7 +156,7 @@
struct stat buf;
- if (0 == stat(name,&buf)) {
+ if (0 == NETPERF_STAT(name,&buf)) {
/* the name resolved where we are - either there is a match in
CWD, or they specified a full path name, I wonder if we need to
worry about explicit null termination of full? raj 2006-02-27 */
@@ -162,9 +169,9 @@
work, we presume that the name given wasn't a full one, so we
just slap the NETPERFDIR and path separator in front of the
name and try again. */
- snprintf(path,PATH_MAX,"%s%s%s",NETPERFDIR,NETPERF_PATH_SEP,name);
+ NETPERF_SNPRINTF(path,PATH_MAX,"%s%s%s",NETPERFDIR,NETPERF_PATH_SEP,name);
path[PATH_MAX] = '\0';
- if (0 == stat(path,&buf)) {
+ if (0 == NETPERF_STAT(path,&buf)) {
strncpy(full,path,fulllen);
full[fulllen-1] = '\0';
ret = strlen(full);
@@ -201,7 +208,7 @@
}
-#else
+#elif defined HAVE_GETTIMEOFDAY
void
netperf_timestamp(struct timeval *timestamp)
@@ -253,6 +260,36 @@
return(usecs/1000);
}
+#else
+
+void
+netperf_timestamp(struct timeval *timestamp)
+{
+ timestamp->tv_sec = 0;
+ timestamp->tv_usec = 0;
+}
+
+ /* return the difference (in micro seconds) between two timeval */
+ /* timestamps */
+int
+delta_micro(struct timeval *begin,struct timeval *end)
+
+{
+
+ return(1000000000);
+
+}
+ /* return the difference (in milliseconds) between two timeval
+ timestamps */
+int
+delta_milli(struct timeval *begin,struct timeval *end)
+
+{
+
+ return(1000000000);
+
+}
+
#endif /* HAVE_GETHRTIME */
/* This routine will return the two arguments to the calling routine. */
@@ -768,6 +805,7 @@
char full_path[PATH_MAX];
char *last;
char *s;
+ struct stat buf;
/* if we have no environment variables, this will not be
@@ -797,11 +835,29 @@
}
if (NULL != ld_library_path) {
+#ifdef WITH_GLIB
+ gchar **tokens;
+ int tok;
+#endif
/* OK, start trapsing down the path until we find a match */
strcpy(ld_library_path,temp);
+#ifdef WITH_GLIB
+ tokens = g_strsplit(ld_library_path,":",15);
+ for (tok = 0; tokens[tok] != NULL; tok++) {
+ g_snprintf(full_path,PATH_MAX,"%s%s%s",temp,NETPERF_PATH_SEP,la);
+ if (g_stat(full_path,&buf) == 0) {
+ /* we have a winner, time to go */
+ break;
+ }
+ else {
+ /* put-back the original la file */
+ strncpy(full_path,(char *)la,PATH_MAX);
+ }
+ }
+ g_strfreev(tokens);
+#else
s = ld_library_path;
while ((temp = strtok_r(s,":",&last)) != NULL) {
- struct stat buf;
s = NULL;
snprintf(full_path,PATH_MAX,"%s%s%s",temp,NETPERF_PATH_SEP,la);
if (stat(full_path,&buf) == 0) {
@@ -813,6 +869,7 @@
strncpy(full_path,(char *)la,PATH_MAX);
}
}
+#endif
}
/* so, after all that, is it really a ".la" file or is it some other
@@ -890,16 +947,25 @@
GenReport
get_report_function(xmlNodePtr cmd)
{
- int tmp = debug;
xmlChar *la_file;
char lib_file[NETPERF_MAX_TEST_LIBRARY_NAME];
- void *lib_handle;
xmlChar *fname;
GenReport func;
+#ifdef WITH_GLIB
+ gboolean ret;
+ GModule *lib_handle;
+#else
+ void *lib_handle;
+#endif
+
+ /* first we do the xml stuff */
la_file = xmlGetProp(cmd, (const xmlChar *)"library");
+ fname = xmlGetProp(cmd, (const xmlChar *)"function");
+
map_la_to_lib(la_file,lib_file);
+
if (debug) {
fprintf(where,
"trying to open library file '%s' via '%s'\n",
@@ -907,26 +973,45 @@
(char *)la_file);
fflush(where);
}
+
+ /* now we do the dlopen/gmodule magic */
+
+#ifdef WITH_GLIB
+ lib_handle = g_module_open((const gchar *)lib_file,0);
+#else
lib_handle = dlopen((char *)lib_file, RTLD_NOW || RTLD_GLOBAL);
+#endif
if (debug) {
fprintf(where,"open of library file '%s' returned %p\n",
(char *)lib_file, lib_handle);
if (lib_handle == NULL) {
+#ifdef WITH_GLIB
+ fprintf(where,"g_module_open error '%s'\n",g_module_error());
+#else
fprintf (where,"dlopen error '%s'\n",dlerror());
+#endif
}
fflush(where);
}
- fname = xmlGetProp(cmd, (const xmlChar *)"function");
+
+#ifdef WITH_GLIB
+ ret = g_module_symbol(lib_handle,fname,&func);
+#else
func = (GenReport)dlsym(lib_handle,(char *)fname);
+#endif
if (debug) {
- fprintf(where,"dlsym of function '%s' returned %p\n",
+ fprintf(where,"symbol lookup of function '%s' returned %p\n",
fname, func);
if (func == NULL) {
+#ifdef WITH_GLIB
+ fprintf(where,"g_module_symbol error '%s'\n",g_module_error());
+#else
fprintf (where,"dlsym error '%s'\n",dlerror());
+#endif
}
fflush(where);
}
- debug = tmp;
+
return(func);
}
@@ -934,7 +1019,12 @@
get_test_function(test_t *test, const xmlChar *func)
{
int tmp = debug;
+#ifdef WITH_GLIB
+ GModule *lib_handle = test->library_handle;
+ gboolean ret;
+#else
void *lib_handle = test->library_handle;
+#endif
xmlChar *fname;
void *fptr = NULL;
int fnlen = 0;
@@ -960,12 +1050,20 @@
(char *)la_file);
fflush(where);
}
+#ifdef WITH_GLIB
+ lib_handle = g_module_open((const gchar *)lib_file,0);
+#else
lib_handle = dlopen((char *)lib_file, RTLD_NOW || RTLD_GLOBAL);
+#endif
if (debug) {
- fprintf(where,"dlopen of library file '%s' returned handle %p\n",
+ fprintf(where,"open of library file '%s' returned handle %p\n",
(char *)lib_file, lib_handle);
if (lib_handle == NULL) {
- fprintf (where,"dlopen error '%s'\n",dlerror());
+#ifdef WITH_GLIB
+ fprintf(where,"g_module_open error '%s'\n",g_module_error());
+#else
+ fprintf(where,"dlopen error '%s'\n",dlerror());
+#endif
}
fflush(where);
}
@@ -1007,21 +1105,21 @@
}
if (!xmlStrcmp(func,(const xmlChar *)"test_clear")) {
- if (strlen("_clear_stats") < (NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
+ if (strlen("_clear_stats") < (size_t)(NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
strcat(func_name,"_clear_stats");
rc = NPE_SUCCESS;
} else {
rc = NPE_FUNC_NAME_TOO_LONG;
}
} else if (!xmlStrcmp(func,(const xmlChar *)"test_stats")) {
- if (strlen("_get_stats") < (NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
+ if (strlen("_get_stats") < (size_t)(NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
strcat(func_name,"_get_stats");
rc = NPE_SUCCESS;
} else {
rc = NPE_FUNC_NAME_TOO_LONG;
}
} else if (!xmlStrcmp(func,(const xmlChar *)"test_decode")) {
- if (strlen("_decode_stats") < (NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
+ if (strlen("_decode_stats") < (size_t)(NETPERF_MAX_TEST_FUNCTION_NAME-tnlen)) {
strcat(func_name,"_decode_stats");
rc = NPE_SUCCESS;
} else {
@@ -1036,12 +1134,20 @@
fflush(where);
}
if (rc == NPE_SUCCESS) {
+#ifdef WITH_GLIB
+ ret = g_module_symbol(lib_handle,func_name,&fptr);
+#else
fptr = dlsym(lib_handle,func_name);
+#endif
if (debug) {
- fprintf(where,"dlsym of func_name '%s' returned %p\n",
+ fprintf(where,"symbol lookup of func_name '%s' returned %p\n",
func_name, fptr);
if (fptr == NULL) {
+#ifdef WITH_GLIB
+ fprintf(where,"g_module_symbol error '%s'\n",g_module_error());
+#else
fprintf (where,"dlsym error '%s'\n",dlerror());
+#endif
}
fflush(where);
}
@@ -1187,7 +1293,7 @@
int
establish_listen(char *hostname, char *service, int af, netperf_socklen_t *addrlenp)
{
- int sockfd;
+ SOCKET sockfd;
int error;
int count;
int len = *addrlenp;
@@ -1221,7 +1327,11 @@
fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
fflush(where);
}
+#ifdef WITH_GLIB
+ g_usleep(1000);
+#else
sleep(1);
+#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
@@ -1248,14 +1358,15 @@
sockfd = socket(res_temp->ai_family,
res_temp->ai_socktype,
res_temp->ai_protocol);
- if (sockfd < 0) {
+ if (sockfd == INVALID_SOCKET) {
if (debug) {
- fprintf(where,"establish_listen: socket error try next one\n");
+ fprintf(where,"establish_listen: socket error trying next one\n");
fflush(where);
}
continue;
}
- if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one)) == -1) {
+ if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one)) ==
+ SOCKET_ERROR) {
fprintf(where,"establish_listen: SO_REUSEADDR failed\n");
fflush(where);
}
@@ -1361,7 +1472,11 @@
fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
fflush(where);
}
+#ifdef WITH_GLIB
+ g_usleep(1000);
+#else
sleep(1);
+#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
@@ -1402,7 +1517,11 @@
count);
fflush(where);
}
+#ifdef WITH_GLIB
+ g_usleep(1000);
+#else
sleep(1);
+#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
Modified: trunk/src/netlib.h
===================================================================
--- trunk/src/netlib.h 2006-03-07 21:28:56 UTC (rev 77)
+++ trunk/src/netlib.h 2006-03-08 01:31:09 UTC (rev 78)
@@ -51,6 +51,10 @@
#include <sys/socket.h>
#endif
+#ifndef WIN32
+#define SOCKET int
+#endif
+
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
Modified: trunk/src/netperf.h
===================================================================
--- trunk/src/netperf.h 2006-03-07 21:28:56 UTC (rev 77)
+++ trunk/src/netperf.h 2006-03-08 01:31:09 UTC (rev 78)
@@ -40,8 +40,38 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
+/* still more nested includes to get the uint stuff... */
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+# include <stdint.h>
+# else
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+# endif
+#endif
+
+/* under Windows we need to get the magic for "SOCKET" and one of
+ these next three does it */
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+
#ifdef WITH_GLIB
#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gprintf.h>
#define NETPERF_MUTEX_T GMutex
#define NETPERF_RWLOCK_T GStaticRWLock
#define NETPERF_THREAD_T GThread *
@@ -54,6 +84,8 @@
#define NETPERF_COND_BROADCAST g_cond_broadcast
#define NETPERF_RWLOCK_WRLOCK g_static_rw_lock_writer_lock
#define NETPERF_RWLOCK_WRITER_UNLOCK g_static_rw_lock_writer_unlock
+#define NETPERF_STAT g_stat
+#define NETPERF_SNPRINTF g_snprintf
#elif defined(HAVE_PTHREAD_H)
#include <pthread.h>
#define NETPERF_MUTEX_T pthread_mutex_t
@@ -68,15 +100,12 @@
#define NETPERF_COND_BROADCAST pthread_cond_broadcast
#define NETPERF_RWLOCK_WRLOCK pthread_rwlock_wrlock
#define NETPERF_RWLOCK_WRITER_UNLOCK pthread_rwlock_unlock
+#define NETPERF_STAT stat
+#define NETPERF_SNPRINTF snprintf
#else
#error Netperf4 requires either glib or pthreads
#endif
-/* we want to get the definition of uint32_t et al */
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-
#ifdef WANT_HISTOGRAM
#include "netperf_hist.h"
#else
@@ -87,10 +116,16 @@
#define NETPERF_DEBUG_LOG_DIR "c:\\temp\\"
#define NETPERF_DEBUG_LOG_PREFIX "netperf"
#define NETPERF_DEBUG_LOG_SUFFIX ".log"
+#define netperf_socklen_t socklen_t
+#define close(x) closesocket(x)
+#define strcasecmp(a,b) _stricmp(a,b)
+#define getpid() ((int)GetCurrentProcessId())
#else
#define NETPERF_DEBUG_LOG_DIR "/tmp/"
#define NETPERF_DEBUG_LOG_PREFIX "netperf"
#define NETPERF_DEBUG_LOG_SUFFIX ".log"
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR -1
#endif
#include "netconfidence.h"
@@ -180,7 +215,7 @@
xmlNodePtr node; /* the xml document node containing the
servers configuration data */
- int sock; /* the socket over which we communicate
+ SOCKET sock; /* the socket over which we communicate
with the server */
ns_state_t state; /* in what state is this server
Modified: trunk/src/netsysstats_common.c
===================================================================
--- trunk/src/netsysstats_common.c 2006-03-07 21:28:56 UTC (rev 77)
+++ trunk/src/netsysstats_common.c 2006-03-08 01:31:09 UTC (rev 78)
@@ -42,6 +42,7 @@
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
+
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
More information about the netperf-dev
mailing list