[netperf-dev] netperf4 commit notice r31 - trunk/src
burger at netperf.org
burger at netperf.org
Wed Dec 7 13:17:28 PST 2005
Author: burger
Date: 2005-12-07 13:17:25 -0800 (Wed, 07 Dec 2005)
New Revision: 31
Modified:
trunk/src/netlib.c
trunk/src/netlib.h
trunk/src/netmsg.c
trunk/src/netperf.c
trunk/src/netperf.h
trunk/src/netserver.c
trunk/src/nettest_vst.c
Log:
Fixed additional timing problem in nettest_vst.c
Added capability to have tests die and be removed from netperf and netservers.
Also added the capability to close netserver connections.
An exit message also exists which can be used to shutdown netperf.
Stephen Burger
Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netlib.c 2005-12-07 21:17:25 UTC (rev 31)
@@ -415,13 +415,47 @@
return(NPE_SUCCESS);
}
+void
+delete_test(const xmlChar *id)
+{
+ /* the removal of the test from any existing test set is done elsewhere */
+
+ /* we presume that the id is of the form [a-zA-Z][0-9]+ and so will
+ call atoi on id and mod that with the TEST_HASH_BUCKETS */
+
+ int hash_value;
+ test_t *test_pointer;
+ test_t **prev_test;
+
+
+ hash_value = TEST_HASH_VALUE(id);
+
+ /* don't forget to add error checking one day */
+ pthread_mutex_lock(&(test_hash[hash_value].hash_lock));
+
+ prev_test = &(test_hash[hash_value].test);
+ test_pointer = test_hash[hash_value].test;
+ while (test_pointer != NULL) {
+ if (!xmlStrcmp(test_pointer->id,id)) {
+ /* we have a match */
+ *prev_test = test_pointer->next;
+ free(test_pointer);
+ break;
+ }
+ prev_test = &(test_pointer->next);
+ test_pointer = test_pointer->next;
+ }
+
+ pthread_mutex_unlock(&(test_hash[hash_value].hash_lock));
+}
+
test_t *
find_test_in_hash(const xmlChar *id)
{
/* we presume that the id is of the form [a-zA-Z][0-9]+ and so will
call atoi on id and mod that with the TEST_HASH_BUCKETS */
- int hash_value;
+ int hash_value;
test_t *test_pointer;
@@ -1549,3 +1583,13 @@
NP_ERROR_NAMES[i]);
fflush(where);
}
+
+const char *
+netperf_error_name(int rc)
+{
+ int i;
+
+
+ i = rc - NPE_MIN_ERROR_NUM;
+ return(NP_ERROR_NAMES[i]);
+}
Modified: trunk/src/netlib.h
===================================================================
--- trunk/src/netlib.h 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netlib.h 2005-12-07 21:17:25 UTC (rev 31)
@@ -37,9 +37,11 @@
#include <poll.h>
#endif
+extern void delete_test(const xmlChar *id);
extern test_t * find_test_in_hash(const xmlChar *id);
extern void report_test_status(server_t *server);
extern GenReport get_report_function(xmlNodePtr cmd);
+extern const char * netperf_error_name(int rc);
/* do we REALLY want this stuff? */
#ifdef NO_DLOPEN
Modified: trunk/src/netmsg.c
===================================================================
--- trunk/src/netmsg.c 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netmsg.c 2005-12-07 21:17:25 UTC (rev 31)
@@ -54,6 +54,8 @@
int clear_stats_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int clear_sys_stats_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
+int close_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
+int closed_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int configured_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int dead_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int die_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
@@ -64,7 +66,6 @@
int idled_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int initialized_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int interval_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
-int kill_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int load_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int loaded_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
int measure_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server);
@@ -85,7 +86,6 @@
#ifdef OFF
{ "cleared", cleared_message, 0x00000000 },
{ "configured", configured_message, 0x00000000 },
- { "dead", dead_message, 0x00000000 },
#endif
{ "measuring", measuring_message, 0x00000010 },
{ "loaded", loaded_message, 0x00000010 },
@@ -94,6 +94,8 @@
{ "sys_stats", sys_stats_message, 0x00000010 },
{ "initialized", initialized_message, 0x00000018 },
{ "error", error_message, 0x00000018 },
+ { "dead", dead_message, 0x00000018 },
+ { "closed", closed_message, 0x00000018 },
{ "version", np_version_check, 0x00000004 },
{ NULL, unknown_message, 0xFFFFFFFF }
};
@@ -102,10 +104,8 @@
/* Message name, function, StateBitMap */
#ifdef OFF
{ "clear", clear_message, 0x00000000 },
- { "die", die_message, 0x00000000 },
{ "error", error_message, 0x00000000 },
{ "interval", interval_message, 0x00000000 },
- { "kill", kill_message, 0x00000000 },
{ "snap", snap_message, 0x00000000 },
#endif
{ "measure", measure_message, 0x00000010 },
@@ -117,6 +117,8 @@
{ "clear_sys_stats", clear_sys_stats_message, 0x00000010 },
{ "initialized", initialized_message, 0x00000010 },
{ "test", test_message, 0x00000014 },
+ { "die", die_message, 0x00000030 },
+ { "close", close_message, 0x00000030 },
{ "version", ns_version_check, 0x00000001 },
{ NULL, unknown_message, 0xFFFFFFFF }
};
@@ -313,6 +315,57 @@
int
+die_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
+{
+ int rc = NPE_SUCCESS;
+ xmlChar *testid;
+ test_t *test;
+
+
+ testid = xmlGetProp(msg,(const xmlChar *)"tid");
+ test = find_test_in_hash(testid);
+ if (test != NULL) {
+ if (debug) {
+ fprintf(where,"%s: tid = %s prev_state_req = %d ",
+ __func__, testid, test->state_req);
+ fflush(where);
+ }
+ test->state_req = TEST_DEAD;
+ if (debug) {
+ fprintf(where," new_state_req = %d\n",test->state_req);
+ fflush(where);
+ }
+ }
+ return(rc);
+}
+
+
+int
+dead_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
+{
+ xmlChar *testid;
+ test_t *test;
+
+
+ testid = xmlGetProp(msg,(const xmlChar *)"tid");
+ test = find_test_in_hash(testid);
+ if (test != NULL) {
+ if (debug) {
+ fprintf(where,"%s: tid = %s prev_state_req = %d ",
+ __func__, testid, test->state_req);
+ fflush(where);
+ }
+ test->state = TEST_DEAD;
+ if (debug) {
+ fprintf(where," new_state_req = %d\n",test->state_req);
+ fflush(where);
+ }
+ }
+ return(NPE_SUCCESS);
+}
+
+
+int
error_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
{
int loc_debug = 0;
@@ -435,7 +488,8 @@
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "get_stats_message: send_control_message failed\n");
+ "%s: send_control_message failed\n",
+ __func__);
fflush(where);
}
}
@@ -457,7 +511,8 @@
test = find_test_in_hash(testid);
if (test != NULL) {
if (debug) {
- fprintf(where,"get_sys_stats_message: test_state = %d ",test->state);
+ fprintf(where,"%s: test_state = %d ",
+ __func__, test->state);
fflush(where);
}
sys_stats = (test->test_stats)(test);
@@ -468,7 +523,8 @@
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "get_stats_message: send_control_message failed\n");
+ "%s: send_control_message failed\n",
+ __func__);
fflush(where);
}
}
@@ -577,6 +633,50 @@
}
int
+close_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
+{
+ xmlChar *flag;
+
+
+ /* what should we really do with this flag?? sgb 2005-12-5 */
+ flag = xmlGetProp(msg,(const xmlChar *)"flag");
+ if (debug) {
+ fprintf(where,"%s: flag = '%s' state = %d req_state = %d\n",
+ __func__, flag, server->state, server->state_req);
+ fflush(where);
+ }
+ if (!xmlStrcmp(flag,(const xmlChar *)"LOOP")) {
+ server->state_req = NSRV_CLOSE;
+ }
+ else {
+ server->state_req = NSRV_EXIT;
+ }
+ return(NPE_SUCCESS);
+}
+
+int
+closed_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
+{
+ xmlChar *flag;
+
+
+ /* what should we really do with this flag?? sgb 2005-12-5 */
+ flag = xmlGetProp(msg,(const xmlChar *)"flag");
+ if (debug) {
+ fprintf(where,"%s: flag = '%s' state = %d req_state = %d\n",
+ __func__, flag, server->state, server->state_req);
+ fflush(where);
+ }
+ if (!xmlStrcmp(flag,(const xmlChar *)"LOOPING")) {
+ server->state = NSRV_CLOSE;
+ }
+ else {
+ server->state = NSRV_EXIT;
+ }
+ return(NPE_SUCCESS);
+}
+
+int
initialized_message(xmlNodePtr msg, xmlDocPtr doc, server_t *server)
{
Modified: trunk/src/netperf.c
===================================================================
--- trunk/src/netperf.c 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netperf.c 2005-12-07 21:17:25 UTC (rev 31)
@@ -315,13 +315,13 @@
if (rc) {
fprintf(where, "netperf_init: pthread_mutex_init error %d\n",rc);
fflush(where);
- exit;
+ exit(-2);
}
rc = pthread_cond_init(&(server_hash[i].condition), NULL);
if (rc) {
fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
fflush(where);
- exit;
+ exit(-2);
}
}
@@ -331,13 +331,13 @@
if (rc) {
fprintf(where, "netperf_init: pthread_mutex_init error %d\n",rc);
fflush(where);
- exit;
+ exit(-2);
}
rc = pthread_cond_init(&(test_hash[i].condition), NULL);
if (rc) {
fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
fflush(where);
- exit;
+ exit(-2);
}
}
@@ -346,7 +346,7 @@
-void
+static void
display_server_hash()
{
int i;
@@ -363,7 +363,7 @@
}
}
-int
+static int
add_server_to_hash(server_t *new_server) {
int hash_value;
@@ -382,7 +382,40 @@
return(NPE_SUCCESS);
}
-server_t *
+static void
+delete_server(const xmlChar *id)
+{
+ /* we presume that the id is of the form [a-zA-Z][0-9]+ and so will
+ call atoi on id and mod that with the SERVER_HASH_BUCKETS */
+
+ int hash_value;
+ server_t *server_pointer;
+ server_t **prev_server;
+
+
+ hash_value = ((atoi((char *)id + 1)) % SERVER_HASH_BUCKETS);
+
+ /* don't forget to add error checking one day */
+ pthread_mutex_lock(&(server_hash[hash_value].hash_lock));
+
+ prev_server = &(server_hash[hash_value].server);
+ server_pointer = server_hash[hash_value].server;
+ while (server_pointer != NULL) {
+ if (!xmlStrcmp(server_pointer->id,id)) {
+ /* we have a match */
+ *prev_server = server_pointer->next;
+ free(server_pointer);
+ break;
+ }
+ prev_server = &(server_pointer->next);
+ server_pointer = server_pointer->next;
+ }
+
+ pthread_mutex_unlock(&(server_hash[hash_value].hash_lock));
+}
+
+
+static server_t *
find_server_in_hash(const xmlChar *id) {
/* we presume that the id is of the form [a-zA-Z][0-9]+ and so will
@@ -411,7 +444,7 @@
}
-int
+static int
add_test_set_to_hash(tset_t *new_test_set)
{
int hash_value;
@@ -430,7 +463,7 @@
return(NPE_SUCCESS);
}
-int
+static int
delete_test_set_from_hash(const xmlChar *id)
{
/* we presume that the id is of the form [s][0-9]+ and so will
@@ -466,7 +499,7 @@
return(NPE_SUCCESS);
}
-tset_t *
+static tset_t *
find_test_set_in_hash(const xmlChar *id)
{
/* we presume that the id is of the form [s][0-9]+ and so will
@@ -622,7 +655,7 @@
fprintf(where, "instaniate_netservers: ");
fprintf(where, "pthread_rwlock_init error %d\n", rc);
fflush(where);
- rc == NPE_PTHREAD_RWLOCK_INIT_FAILED;
+ rc = NPE_PTHREAD_RWLOCK_INIT_FAILED;
}
if (rc == NPE_SUCCESS) {
rc = instantiate_tests(this_netserver, new_server);
@@ -900,6 +933,7 @@
NETPERF_DEBUG_EXIT(debug,where);
+ return(test);
}
@@ -1006,6 +1040,7 @@
}
pthread_mutex_unlock(server->lock);
+ return(server);
}
@@ -1122,17 +1157,16 @@
}
-static int
+static void
wait_for_tests_to_enter_requested_state(xmlNodePtr cmd)
{
- const char* fnc = "wait_for_tests_to_enter_requested_state";
int rc = NPE_SUCCESS;
xmlChar *tid;
test_t *test;
tset_t *test_set;
if (debug) {
- fprintf(where,"entering %s\n",fnc);
+ fprintf(where,"entering %s\n", __func__);
fflush(where);
}
tid = xmlGetProp(cmd, (const xmlChar *)"tid");
@@ -1165,7 +1199,7 @@
}
}
if (debug) {
- fprintf(where,"exiting %s rc = %d\n",fnc,rc);
+ fprintf(where,"exiting %s rc = %d\n", __func__, rc);
fflush(where);
}
}
@@ -1725,6 +1759,35 @@
static int
+close_command(xmlNodePtr cmd, uint32_t junk)
+{
+ int rc;
+ xmlChar *sid;
+ server_t *server;
+
+ sid = xmlGetProp(cmd,(const xmlChar *)"sid");
+ server = find_server_in_hash(sid);
+ xmlSetProp(cmd,(const xmlChar *)"sid", server->id);
+ rc = send_control_message(server->sock,
+ cmd,
+ server->id,
+ my_nid);
+ if (rc != NPE_SUCCESS) {
+ server->state = NSRV_ERROR;
+ server->err_rc = rc;
+ server->err_fn = (char *)__func__;
+ }
+ while ((server->state != NSRV_ERROR) &&
+ (server->state != NSRV_CLOSE) &&
+ (server->state != NSRV_EXIT )) {
+ sleep(1);
+ }
+ delete_server(sid);
+ return(rc);
+}
+
+
+static int
unknown_command(xmlNodePtr cmd, uint32_t junk)
{
fprintf(where,"process_command: unknown command in file %s\n",cname);
@@ -1763,10 +1826,11 @@
{ "delete_test_set", delete_test_set, 0 },
{ "show_test_set", show_test_set, 0 },
{ "comment", comment_command, 0 },
+ { "close", close_command, 0 },
{ "exit", exit_netperf_command, 0 },
{ "exec_local", exec_local_command, 0 },
{ "exec_remote", exec_remote_command, 0 },
- { "unknown", unknown_command, 0 }
+ { NULL, unknown_command, 0 }
};
static int
@@ -1831,7 +1895,12 @@
commands = parse_xml_file(iname, (const xmlChar *)"commands", &doc);
/* execute commands and events in a loop */
- cmd = commands->xmlChildrenNode;
+ if (commands != NULL) {
+ cmd = commands->xmlChildrenNode;
+ }
+ else {
+ cmd = NULL;
+ }
while (cmd != NULL && rc == NPE_SUCCESS) {
if (debug) {
fprintf(where,"process_commands_and_events: calling process_command\n");
@@ -1867,13 +1936,12 @@
main(int argc, char **argv)
{
int rc = NPE_SUCCESS;
- int tmp;
program_name = argv[0];
where = stderr;
- tmp = decode_switches(argc, argv);
+ decode_switches(argc, argv);
xmlInitParser();
xmlKeepBlanksDefault(0);
Modified: trunk/src/netperf.h
===================================================================
--- trunk/src/netperf.h 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netperf.h 2005-12-07 21:17:25 UTC (rev 31)
@@ -40,12 +40,25 @@
#define NO_STATE_CHANGE(test) (test->state_req == test->new_state)
#define SET_TEST_DATA(test,ptr) test->test_specific_data = ptr
-#ifndef WIN32
+
+#ifdef WIN32
+#define CHECK_FOR_NOT_SOCKET (WSAGetLastError() == WSAENOTSOCK)
+#define CHECK_FOR_INVALID_SOCKET (temp_socket == INVALID_SOCKET)
+#define CHECK_FOR_RECV_ERROR(len) (len == SOCKET_ERROR)
+#define CHECK_FOR_SEND_ERROR(len) (len >=0) || (len == SOCKET_ERROR && WSAGetLas
+tError() == WSAEINTR)
+#define GET_ERRNO WSAGetLastError()
+#define NETPERF_PATH_SEP "\\"
+#else
+#define CHECK_FOR_NOT_SOCKET (errno == ENOTSOCK)
+#define CHECK_FOR_INVALID_SOCKET (temp_socket < 0)
+#define CHECK_FOR_RECV_ERROR(len) (len < 0)
+#define CHECK_FOR_SEND_ERROR(len) (len >=0) || (errno == EINTR)
+#define GET_ERRNO errno
#define NETPERF_PATH_SEP "/"
-#else
-#define NETPERF_PATH_SEP "\\"
#endif
+
#ifdef HAVE_GETHRTIME
#define NETPERF_TIMESTAMP_T hrtime_t
#else
@@ -62,7 +75,9 @@
NSRV_VERS,
NSRV_INIT,
NSRV_WORK,
- NSRV_ERROR
+ NSRV_ERROR,
+ NSRV_CLOSE,
+ NSRV_EXIT
} ns_state_t;
typedef struct server_instance {
@@ -367,6 +382,7 @@
NPE_SUCCESS = 0
};
+
#ifdef NETLIB
const char *NP_ERROR_NAMES[] = {
Modified: trunk/src/netserver.c
===================================================================
--- trunk/src/netserver.c 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/netserver.c 2005-12-07 21:17:25 UTC (rev 31)
@@ -266,6 +266,39 @@
}
+void
+delete_netperf(const xmlChar *id)
+{
+
+ /* we presume that the id is of the form [a-zA-Z][0-9]+ and so will
+ call atoi on id and mod that with the SERVER_HASH_BUCKETS */
+
+ int hash_value;
+ server_t *server_pointer;
+ server_t **prev_server;
+
+ hash_value = 0;
+
+ /* don't forget to add error checking one day */
+ pthread_mutex_lock(&(netperf_hash[hash_value].hash_lock));
+
+ prev_server = &(netperf_hash[hash_value].server);
+ server_pointer = netperf_hash[hash_value].server;
+ while (server_pointer != NULL) {
+ if (!xmlStrcmp(server_pointer->id,id)) {
+ /* we have a match */
+ *prev_server = server_pointer->next;
+ free(server_pointer);
+ break;
+ }
+ prev_server = &(server_pointer->next);
+ server_pointer = server_pointer->next;
+ }
+
+ pthread_mutex_unlock(&(netperf_hash[hash_value].hash_lock));
+}
+
+
server_t *
find_netperf_in_hash(const xmlChar *id)
{
@@ -326,7 +359,7 @@
if (xmlStrcmp(cur->name,(const xmlChar *)"version")!=0) {
if (debug) {
fprintf(where,
- "instantiate_netperf: Received an unexpected message\n");
+ "%s: Received an unexpected message\n", __func__);
fflush(where);
}
rc = NPE_UNEXPECTED_MSG;
@@ -336,7 +369,7 @@
from_nid = xmlStrdup(xmlGetProp(msg,(const xmlChar *)"fromnid"));
if ((netperf = (server_t *)malloc(sizeof(server_t))) == NULL) {
- fprintf(where,"instantiate_netperf: malloc failed\n");
+ fprintf(where,"%s: malloc failed\n", __func__);
fflush(where);
exit(1);
}
@@ -355,7 +388,7 @@
}
else {
if (debug) {
- fprintf(where,"instantiate_netperf: close connection remote close\n");
+ fprintf(where,"%s: close connection remote close\n", __func__);
fflush(where);
}
close(sock);
@@ -412,6 +445,7 @@
}
+
static void
check_test_state()
{
@@ -423,6 +457,7 @@
test_hash_t *h;
xmlNodePtr msg = NULL;
xmlNodePtr new_node;
+ xmlChar *id;
server_t *netperf;
char code[8];
@@ -439,8 +474,8 @@
if (orig != new) {
/* report change in test state */
if (debug) {
- fprintf(where,"check_test_state:tid = %s state %d new_state %d\n",
- test->id, orig, new);
+ fprintf(where,"%s:tid = %s state %d new_state %d\n",
+ __func__, test->id, orig, new);
fflush(where);
}
switch (new) {
@@ -476,6 +511,7 @@
case TEST_DEAD:
msg = xmlNewNode(NULL,(xmlChar *)"dead");
xmlSetProp(msg,(xmlChar *)"tid",test->id);
+ id = test->id;
break;
default:
break;
@@ -486,22 +522,105 @@
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "check_test_state: send_control_message failed\n");
+ "%s: send_control_message failed\n", __func__);
fflush(where);
}
}
}
}
test = test->next;
+ if (new == TEST_DEAD) {
+ delete_test(id);
+ }
}
/* mutex unlocking is not required because only one
netserver thread looks at these data structures sgb */
}
}
+
+
static void
-handle_netperf_requests()
+kill_all_tests()
{
+ int i;
+ int empty_hash_buckets;
+ test_t *test;
+ test_hash_t *h;
+
+
+ for (i = 0; i < TEST_HASH_BUCKETS; i ++) {
+ h = &test_hash[i];
+ /* mutex locking is not required because only one
+ netserver thread looks at these data structures sgb */
+ test = h->test;
+ while (test != NULL) {
+ /* tell each test to die */
+ test->state_req = TEST_DEAD;
+ test = test->next;
+ }
+ }
+ empty_hash_buckets = 0;
+ while(empty_hash_buckets < TEST_HASH_BUCKETS) {
+ empty_hash_buckets = 0;
+ sleep(1);
+ check_test_state();
+ for (i = 0; i < TEST_HASH_BUCKETS; i ++) {
+ if (test_hash[i].test == NULL) {
+ empty_hash_buckets++;
+ }
+ }
+ }
+}
+
+
+static int
+close_netserver()
+{
+ int rc;
+ int loop;
+ server_t *netperf;
+
+
+ netperf = netperf_hash[0].server;
+ if ((netperf->state_req == NSRV_CLOSE) ||
+ (netperf->state_req == NSRV_EXIT ) ||
+ (netperf->err_rc == NPE_REMOTE_CLOSE)) {
+ xmlNodePtr msg = NULL;
+ kill_all_tests();
+ msg = xmlNewNode(NULL,(xmlChar *)"closed");
+ if (netperf->state_req == NSRV_CLOSE) {
+ xmlSetProp(msg,(xmlChar *)"flag",(const xmlChar *)"LOOPING");
+ loop = 1;
+ }
+ if (netperf->state_req == NSRV_EXIT) {
+ xmlSetProp(msg,(xmlChar *)"flag",(const xmlChar *)"GONE");
+ loop = 0;
+ }
+ if (msg) {
+ rc = send_control_message(netperf->sock, msg, netperf->id, my_nid);
+ if (rc != NPE_SUCCESS) {
+ if (debug) {
+ fprintf(where,
+ "%s: send_control_message failed\n", __func__);
+ fflush(where);
+ }
+ }
+ }
+ delete_netperf(netperf->id);
+ } else {
+ /* we should never really get here sgb 2005-12-06 */
+ fprintf(where, "%s entered through some unknown path!!!!\n", __func__);
+ fflush(where);
+ exit(-2);
+ }
+ return(loop);
+}
+
+
+static int
+handle_netperf_requests(int sock)
+{
int loc_debug = 0;
int rc = NPE_SUCCESS;
struct pollfd fds;
@@ -510,6 +629,16 @@
NETPERF_DEBUG_ENTRY(debug,where);
+ rc = instantiate_netperf(sock);
+ if (rc != NPE_SUCCESS) {
+ fprintf(where,
+ "%s %s: instantiate_netperf error %d\n",
+ program_name,
+ __func__,
+ rc);
+ fflush(where);
+ exit(rc);
+ }
netperf = netperf_hash[0].server;
/* mutex locking is not required because only one
netserver thread looks at these data structures sgb */
@@ -532,7 +661,8 @@
if (rc > 0) {
rc = process_message(netperf, message);
if (rc) {
- fprintf(where,"process_message returned %d %s\n", rc);
+ fprintf(where,"process_message returned %d %s\n",
+ rc, netperf_error_name(rc));
fflush(where);
}
} else {
@@ -541,7 +671,8 @@
if (rc == 0) {
netperf->err_rc = NPE_REMOTE_CLOSE;
} else {
- fprintf(where,"recv_control_message returned %d\n",rc);
+ fprintf(where,"recv_control_message returned %d %s\n",
+ rc, netperf_error_name(rc));
fflush(where);
netperf->err_rc = rc;
}
@@ -560,6 +691,10 @@
netperf->err_rc = rc;
netperf->err_fn = (char *)__func__;
}
+ if ((netperf->state_req == NSRV_CLOSE) ||
+ (netperf->state_req == NSRV_EXIT )) {
+ break;
+ }
}
if (rc != NPE_SUCCESS) {
@@ -567,8 +702,11 @@
}
/* mutex unlocking is not required because only one
netserver thread looks at these data structures sgb */
+ return(close_netserver());
}
+
+
static void
setup_listen_endpoint(char service[]) {
@@ -576,10 +714,10 @@
struct sockaddr *peeraddr = &name;
int namelen = sizeof(name);
int peerlen = namelen;
- int peeraddr_len = namelen;
int sock;
int rc;
int listenfd = 0;
+ int loop = 1;
NETPERF_DEBUG_ENTRY(debug,where);
@@ -598,14 +736,13 @@
&peerlen);
if (listenfd == -1) {
- fprintf(where,"setup_listen_endpoint: failed to open listen socket\n");
+ fprintf(where,"%s: failed to open listen socket\n", __func__);
fflush(where);
exit(1);
}
if (peerlen > namelen) {
peeraddr = (struct sockaddr *)malloc (peerlen);
- peeraddr_len = peerlen;
}
if (!forground) {
@@ -614,11 +751,12 @@
/* loopdeloop */
- for (;;) {
+ while (loop) {
printf("about to accept on socket %d\n",listenfd);
if ((sock = accept(listenfd,peeraddr,&peerlen)) == -1) {
fprintf(where,
- "setup_listen_endpoint: accept failed errno %d %s\n",
+ "%s: accept failed errno %d %s\n",
+ __func__,
errno,
strerror(errno));
fflush(where);
@@ -626,7 +764,8 @@
}
if (debug) {
fprintf(where,
- "setup_listen_endpoint: accepted connection on sock %d\n",
+ "%s: accepted connection on sock %d\n",
+ __func__,
sock);
fflush(where);
}
@@ -636,19 +775,11 @@
if (forground >= 2) {
/* no fork please, eat with our fingers */
printf("forground instantiation\n");
- rc = instantiate_netperf(sock);
- if (rc != NPE_SUCCESS) {
- fprintf(where,
- "setup_listen_endpoint: instantiate_netperf error %d\n",
- rc);
- fflush(where);
- exit;
- }
/* if we get here, before we go back to call accept again,
probably a good idea to close the sock. of course, I'm not
even sure we will ever get here, but hey, what the heck.
raj 2005-11-10 */
- handle_netperf_requests();
+ loop = handle_netperf_requests(sock);
printf("closing sock %d\n",sock);
close(sock);
}
@@ -661,20 +792,12 @@
perror("netserver fork failure");
exit(-1);
case 0:
- /* we are the child, go ahead and instantiate_netserver,
+ /* we are the child, go ahead and handle netperf requests,
however, we really don't need the listenfd to be open, so
go ahead and close it */
printf("child closing %d\n",listenfd);
close(listenfd);
- rc = instantiate_netperf(sock);
- if (rc != NPE_SUCCESS) {
- fprintf(where,
- "setup_listen_endpoint: instantiate_netperf error %d\n",
- rc);
- fflush(where);
- exit;
- }
- handle_netperf_requests();
+ handle_netperf_requests(sock);
/* as the child, if we've no more requests to process - eg
the connection has closed etc, then we might as well just
exit. raj 2005-11-11 */
@@ -703,7 +826,6 @@
struct sockaddr *peeraddr = &name;
int namelen = sizeof(name);
int peerlen = namelen;
- int peeraddr_len = namelen;
NETPERF_DEBUG_ENTRY(debug,where);
@@ -713,15 +835,15 @@
netperf_hash[i].server = NULL;
rc = pthread_mutex_init(&(netperf_hash[i].hash_lock), NULL);
if (rc) {
- fprintf(where, "netperf_init: pthread_mutex_init error %d\n",rc);
+ fprintf(where, "%s: server pthread_mutex_init error %d\n", __func__, rc);
fflush(where);
- exit;
+ exit(rc);
}
rc = pthread_cond_init(&(netperf_hash[i].condition), NULL);
if (rc) {
- fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
+ fprintf(where, "%s: server pthread_cond_init error %d\n", __func__, rc);
fflush(where);
- exit;
+ exit(rc);
}
}
@@ -729,34 +851,27 @@
test_hash[i].test = NULL;
rc = pthread_mutex_init(&(test_hash[i].hash_lock), NULL);
if (rc) {
- fprintf(where, "netserver_init: pthread_mutex_init error %d\n",rc);
+ fprintf(where, "%s: test pthread_mutex_init error %d\n", __func__, rc);
fflush(where);
- exit;
+ exit(rc);
}
rc = pthread_cond_init(&(test_hash[i].condition), NULL);
if (rc) {
- fprintf(where, "server_init: pthread_cond_init error %d\n",rc);
+ fprintf(where, "%s: test pthread_cond_init error %d\n", __func__, rc);
fflush(where);
- exit;
+ exit(rc);
}
}
netlib_init();
}
-
-static void
-accept_netperf_connections()
-{
-}
-
int
main (int argc, char **argv)
{
- int i;
int rc;
int sock;
@@ -764,7 +879,7 @@
where = stdout;
- i = decode_command_line(argc, argv);
+ decode_command_line(argc, argv);
/* do the work */
xmlInitParser();
@@ -790,31 +905,18 @@
if (getsockname(0, &name, &namelen) == -1) {
/* we may not be a child of inetd */
-#ifdef WIN32
- if (WSAGetLastError() == WSAENOTSOCK) {
+ if (CHECK_FOR_NOT_SOCKET) {
setup_listen_endpoint(listen_port);
}
-#else
- if (errno == ENOTSOCK) {
- setup_listen_endpoint(listen_port);
- }
-#endif /* WIN32 */
}
} else {
- /* we are a child of inetd, so just go ahead and do the right
- thing. raj 2005-10-11 */
- /* I wonder if this should be in handle_netperf_requests? */
- rc = instantiate_netperf(sock);
- if (rc != NPE_SUCCESS) {
- fprintf(where,
- "%s main: instantiate_netperf error %d\n",
- program_name,
- rc);
- fflush(where);
- exit;
- }
+ /* we are a child of inetd or some other equivalent daemon,
+ so just go ahead and do the right thing. raj 2005-10-11 */
+ /* netperf2 has a lot of stuff here to set server_socket up correctly
+ I wonder if there is a cleaner way to do that because the code
+ in netperf2 is really hard to follow. sgb 2005-12-5 */
+ sock = 0;
+ handle_netperf_requests(sock);
}
-
- handle_netperf_requests();
}
Modified: trunk/src/nettest_vst.c
===================================================================
--- trunk/src/nettest_vst.c 2005-12-01 22:27:47 UTC (rev 30)
+++ trunk/src/nettest_vst.c 2005-12-07 21:17:25 UTC (rev 31)
@@ -69,19 +69,7 @@
#include "nettest_vst.h"
-#ifdef WIN32
-#define CHECK_FOR_INVALID_SOCKET (temp_socket == INVALID_SOCKET)
-#define CHECK_FOR_RECV_ERROR(len) (len == SOCKET_ERROR)
-#define CHECK_FOR_SEND_ERROR(len) (len >=0) || (len == SOCKET_ERROR && WSAGetLastError() == WSAEINTR)
-#define GET_ERRNO WSAGetLastError()
-#else
-#define CHECK_FOR_INVALID_SOCKET (temp_socket < 0)
-#define CHECK_FOR_RECV_ERROR(len) (len < 0)
-#define CHECK_FOR_SEND_ERROR(len) (len >=0) || (errno == EINTR)
-#define GET_ERRNO errno
-#endif
-
static void
report_test_failure(test, function, err_code, err_string)
test_t *test;
@@ -810,6 +798,7 @@
long key;
int value;
int i;
+ int loc_debug = 0;
my_data = GET_TEST_DATA(test);
dist = my_data->vst_ring->distribution;
@@ -823,7 +812,7 @@
setstate(dist->random_state);
key = random();
value = key % dist->dist_key;
- if (test->debug) {
+ if (test->debug && loc_debug) {
fprintf(test->where, "**** end of pattern reached ******\n");
fprintf(test->where,
"%s: value = %d key = %d\n",
@@ -832,7 +821,7 @@
}
for (i=0; i< dist->num_patterns; i++) {
value = value - dist->dist_count[i];
- if (test->debug) {
+ if (test->debug && loc_debug) {
fprintf(test->where,
"\tdist_count = %d new_value = %d pattern = %d\n",
dist->dist_count[i], value, dist->pattern[i]);
@@ -843,7 +832,7 @@
break;
}
}
- if (test->debug) {
+ if (test->debug && loc_debug) {
fprintf(test->where,
"%s: new ring value %p\n",
__func__, my_data->vst_ring);
@@ -1698,7 +1687,7 @@
my_data = GET_TEST_DATA(test);
- while(NO_STATE_CHANGE(test)) {
+ while (NO_STATE_CHANGE(test)) {
/* recv the request for the test */
req_base = (int *)(
( (long)(my_data->vst_ring->recv_buff_ptr)
@@ -1767,6 +1756,7 @@
if ((len == 0) ||
(new_state == TEST_IDLE)) {
recv_vst_rr_idle_link(test,len);
+ new_state = TEST_IDLE;
}
else {
if (new_state == TEST_MEASURE) {
@@ -1979,7 +1969,7 @@
my_data = GET_TEST_DATA(test);
- while(NO_STATE_CHANGE(test)) {
+ while (NO_STATE_CHANGE(test)) {
/* code to make data dirty macro enabled by DIRTY */
MAKE_DIRTY(my_data,my_data->vst_ring);
/* send data for the test */
@@ -2254,7 +2244,7 @@
"%s: malloc failed can't generate report\n",
__func__);
fflush(outfd);
- exit;
+ exit(-11);
}
}
@@ -2538,7 +2528,7 @@
fflush(test_set->where);
}
stats_for_test = 0;
- while(stats != NULL) {
+ while (stats != NULL) {
/* process all the statistics records for this test */
if (test_set->debug) {
fprintf(test_set->where,"\tfound some statistics");
@@ -2574,7 +2564,7 @@
fprintf(test_set->where,
"exiting netperf now!!\n");
fflush(test_set->where);
- exit;
+ exit(-13);
}
set_elt = set_elt->next;
}
More information about the netperf-dev
mailing list