[netperf-dev] netperf4 commit notice r98 -
branches/glib_migration/src
raj at netperf.org
raj at netperf.org
Fri Mar 24 14:15:27 PST 2006
Author: raj
Date: 2006-03-24 14:15:26 -0800 (Fri, 24 Mar 2006)
New Revision: 98
Modified:
branches/glib_migration/src/netlib.c
branches/glib_migration/src/netlib.h
branches/glib_migration/src/netmsg.c
branches/glib_migration/src/netperf.c
branches/glib_migration/src/netserver.c
Log:
Start using the GIOChannels on the netperf side too. Compiles under linux
but segfaults.
Modified: branches/glib_migration/src/netlib.c
===================================================================
--- branches/glib_migration/src/netlib.c 2006-03-24 19:54:33 UTC (rev 97)
+++ branches/glib_migration/src/netlib.c 2006-03-24 22:15:26 UTC (rev 98)
@@ -1928,6 +1928,150 @@
return(FALSE);
}
+int
+write_to_control_connection(GIOChannel *source,
+ xmlNodePtr body,
+ xmlChar *nid,
+ const xmlChar *fromnid) {
+
+ int rc;
+ int32_t length;
+
+ gchar *chars_to_send;
+
+ xmlDocPtr doc;
+ xmlDtdPtr dtd;
+ xmlNodePtr message_header;
+ xmlNodePtr new_node;
+ char *control_message;
+ int control_message_len;
+ gsize bytes_written;
+ GError *error = NULL;
+ GIOStatus status;
+
+ if (debug) {
+ fprintf(where,
+ "%s: called with channel %p and message node at %p",
+ __func__,
+ source,
+ body);
+ fprintf(where,
+ " type %s destined for nid %s from nid %s\n",
+ body->name,
+ nid,
+ fromnid);
+ fflush(where);
+ }
+
+ if ((doc = xmlNewDoc((xmlChar *)"1.0")) != NULL) {
+ /* zippity do dah */
+ doc->standalone = 0;
+ dtd = xmlCreateIntSubset(doc,(xmlChar *)"message",NULL,NETPERF_DTD_FILE);
+ if (dtd != NULL) {
+ if (((message_header = xmlNewNode(NULL,(xmlChar *)"message")) != NULL) &&
+ (xmlSetProp(message_header,(xmlChar *)"tonid",nid) != NULL) &&
+ (xmlSetProp(message_header,(xmlChar *)"fromnid",fromnid) != NULL)) {
+ /* zippity ay */
+ xmlDocSetRootElement(doc,message_header);
+ /* it certainly would be nice to not have to do this with two
+ calls... raj 2003-02-28 */
+ if (((new_node = xmlDocCopyNode(body,doc,1)) != NULL) &&
+ (xmlAddChild(message_header, new_node) != NULL)) {
+ /* IF there were a call where I could specify the buffer,
+ then we wouldn't have to copy this again to get things
+ contiguous with the "header" - then again, if the glib IO
+ channel stuff offered a gathering write call it wouldn't
+ matter... raj 2006-03-24 */
+ xmlDocDumpMemory(doc,
+ (xmlChar **)&control_message,
+ &control_message_len);
+ if (control_message_len > 0) {
+ /* what a wonderful day */
+
+ chars_to_send = g_malloc(length+NETPERF_MESSAGE_HEADER_SIZE);
+
+ /* if glib IO channels offered a gathering write, this
+ silliness wouldn't be necessary. yes, they offer
+ buffered I/O and I could do two writes and then a
+ flush, but dagnabit, if I could just call sendmsg()
+ before, so no extra copies, no flushes, it certainly
+ would be nice to be able to do the same with an IO
+ channel. raj 2006-03-24 */
+
+ /* the message length send via the network does not include
+ the length itself... raj 2003-02-27 */
+ length = htonl(strlen(control_message));
+
+ /* first copy the "header" ... */
+ memcpy(chars_to_send,
+ &length,
+ NETPERF_MESSAGE_HEADER_SIZE);
+ if (debug) {
+ g_fprintf(where,
+ "%s copied %d bytes to %p\n",
+ __func__,
+ NETPERF_MESSAGE_HEADER_SIZE,
+ chars_to_send);
+ }
+ /* ... now copy the "data" */
+ memcpy(chars_to_send+NETPERF_MESSAGE_HEADER_SIZE,
+ control_message,
+ control_message_len);
+
+ if (debug) {
+ g_fprintf(where,
+ "%s copied %d bytes to %p\n",
+ __func__,
+ control_message_len,
+ chars_to_send+NETPERF_MESSAGE_HEADER_SIZE);
+ }
+
+ /* and finally, send the data */
+ status = g_io_channel_write_chars(source,
+ chars_to_send,
+ control_message_len +
+ NETPERF_MESSAGE_HEADER_SIZE,
+ &bytes_written,
+ &error);
+
+ if (debug) {
+ /* first display the header */
+ fprintf(where, "Sending %d byte message\n",
+ control_message_len);
+ fprintf(where, "|%*s| ",control_message_len,control_message);
+ fflush(where);
+ }
+ if (bytes_written ==
+ (control_message_len+NETPERF_MESSAGE_HEADER_SIZE)) {
+ if (debug) {
+ fprintf(where,"was successful\n");
+ }
+ rc = NPE_SUCCESS;
+ } else {
+ rc = NPE_SEND_CTL_MSG_FAILURE;
+ if (debug) {
+ fprintf(where,"failed\n");
+ }
+ }
+ } else {
+ rc = NPE_SEND_CTL_MSG_XMLDOCDUMPMEMORY_FAILED;
+ }
+ } else {
+ rc = NPE_SEND_CTL_MSG_XMLCOPYNODE_FAILED;
+ }
+ } else {
+ rc = NPE_SEND_CTL_MSG_XMLNEWNODE_FAILED;
+ }
+ } else {
+ rc = NPE_SEND_CTL_MSG_XMLNEWDTD_FAILED;
+ }
+ } else {
+ rc = NPE_SEND_CTL_MSG_XMLNEWDOC_FAILED;
+ }
+ return(rc);
+
+}
+
gboolean
read_from_control_connection(GIOChannel *source, GIOCondition condition, gpointer data) {
message_state_t *message_state;
Modified: branches/glib_migration/src/netlib.h
===================================================================
--- branches/glib_migration/src/netlib.h 2006-03-24 19:54:33 UTC (rev 97)
+++ branches/glib_migration/src/netlib.h 2006-03-24 22:15:26 UTC (rev 98)
@@ -102,6 +102,10 @@
extern int add_test_to_hash(test_t *new_test);
extern int send_control_message(const int control_sock, xmlNodePtr body,
xmlChar *nid, const xmlChar *fromnid);
+extern int write_to_control_connection(GIOChannel *channel,
+ xmlNodePtr body,
+ xmlChar *nid,
+ const xmlChar *fromnid);
extern int32_t recv_control_message(int control_sock, xmlDocPtr *message);
extern void report_server_error(server_t *server);
#ifdef WITH_GLIB
Modified: branches/glib_migration/src/netmsg.c
===================================================================
--- branches/glib_migration/src/netmsg.c 2006-03-24 19:54:33 UTC (rev 97)
+++ branches/glib_migration/src/netmsg.c 2006-03-24 22:15:26 UTC (rev 98)
@@ -270,14 +270,14 @@
(xmlSetProp(message,(xmlChar *)"fix", NETPERF_FIX) != NULL)) {
/* still smiling */
/* almost there... */
- rc = send_control_message(server->sock,
- message,
- server->id,
- fromnid);
+ rc = write_to_control_connection(server->source,
+ message,
+ server->id,
+ fromnid);
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "send_version_message: send_control_message failed\n");
+ "send_version_message: write_to_control_connection failed\n");
fflush(where);
}
}
@@ -502,14 +502,14 @@
fflush(where);
}
stats = (test->test_stats)(test);
- rc = send_control_message(server->sock,
- stats,
- server->id,
- server->my_nid);
+ rc = write_to_control_connection(server->source,
+ stats,
+ server->id,
+ server->my_nid);
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "%s: send_control_message failed\n",
+ "%s: write_to_control_connection failed\n",
__func__);
fflush(where);
}
@@ -537,14 +537,14 @@
fflush(where);
}
sys_stats = (test->test_stats)(test);
- rc = send_control_message(server->sock,
- sys_stats,
- server->id,
- server->my_nid);
+ rc = write_to_control_connection(server->source,
+ sys_stats,
+ server->id,
+ server->my_nid);
if (rc != NPE_SUCCESS) {
if (debug) {
fprintf(where,
- "%s: send_control_message failed\n",
+ "%s: write_to_control_connection failed\n",
__func__);
fflush(where);
}
Modified: branches/glib_migration/src/netperf.c
===================================================================
--- branches/glib_migration/src/netperf.c 2006-03-24 19:54:33 UTC (rev 97)
+++ branches/glib_migration/src/netperf.c 2006-03-24 22:15:26 UTC (rev 98)
@@ -558,8 +558,8 @@
server = server_hash[i].server;
fprintf(where,"server_hash_bucket[%d]=%p\n",i,server_hash[i].server);
while (server) {
- fprintf(where,"\tserver->id %s, server->sock %d, server->state %d\n",
- server->id,server->sock,server->state);
+ fprintf(where,"\tserver->id %s, server->channel %p, server->state %d\n",
+ server->id,server->source,server->state);
server = server->next;
}
fflush(where);
@@ -828,6 +828,8 @@
xmlNodePtr this_netserver;
server_t *new_server;
xmlChar *netserverid;
+ GIOStatus status;
+ GError *error = NULL;
/* first, get the netperf element which was checked at parse time. The
netperf element has only netserver elements each with its own unique
@@ -882,6 +884,37 @@
new_server->state_req = NSRV_PREINIT;
rc = NPE_CONNECT_FAILED;
}
+#ifdef G_OS_WIN32
+ new_server->source = g_io_channel_win32_new_socket(new_server->sock);
+#else
+ new_server->source = g_io_channel_unix_new(new_server->sock);
+#endif
+ status = g_io_channel_set_flags(new_server->source,
+ G_IO_FLAG_NONBLOCK,
+ &error);
+ if (error) {
+ g_warning("g_io_channel_set_flags %s %d %s\n",
+ g_quark_to_string(error->domain),
+ error->code,
+ error->message);
+ g_clear_error(&error);
+ }
+ g_fprintf(where,
+ "status after set flags %d new_server->source %p\n",
+ status,
+ new_server->source);
+
+ status = g_io_channel_set_encoding(new_server->source,NULL,&error);
+ if (error) {
+ g_warning("g_io_channel_set_encoding %s %d %s\n",
+ g_quark_to_string(error->domain),
+ error->code,
+ error->message);
+ g_clear_error(&error);
+ }
+
+ g_io_channel_set_buffered(new_server->source,FALSE);
+
new_server->state = NSRV_CONNECTED;
new_server->state_req = NSRV_CONNECTED;
rc = send_version_message(new_server, my_nid);
@@ -1147,10 +1180,10 @@
}
/* is the lock around the send required? */
NETPERF_RWLOCK_WRLOCK(&server->rwlock);
- rc = send_control_message(server->sock,
- msg,
- server->id,
- my_nid);
+ rc = write_to_control_connection(server->source,
+ msg,
+ server->id,
+ my_nid);
NETPERF_RWLOCK_WRITER_UNLOCK(&server->rwlock);
} else {
if (debug) {
@@ -1527,10 +1560,10 @@
server = find_server_in_hash(test->server_id);
test->state_req = state;
xmlSetProp(cmd,(const xmlChar *)"tid", test->id);
- rc = send_control_message(server->sock,
- cmd,
- server->id,
- my_nid);
+ rc = write_to_control_connection(server->source,
+ cmd,
+ server->id,
+ my_nid);
if (rc != NPE_SUCCESS) {
test->state = TEST_ERROR;
test->err_rc = rc;
@@ -1551,10 +1584,10 @@
server = find_server_in_hash(test->server_id);
test->state_req = state;
xmlSetProp(cmd,(const xmlChar *)"tid", test->id);
- rc = send_control_message(server->sock,
- cmd,
- server->id,
- my_nid);
+ rc = write_to_control_connection(server->source,
+ cmd,
+ server->id,
+ my_nid);
if (rc != NPE_SUCCESS) {
test->state = TEST_ERROR;
test->err_rc = rc;
@@ -1973,10 +2006,10 @@
}
server = find_server_in_hash(test->server_id);
xmlSetProp(cmd,(const xmlChar *)"tid", test->id);
- rc = send_control_message(server->sock,
- cmd,
- server->id,
- my_nid);
+ rc = write_to_control_connection(server->source,
+ cmd,
+ server->id,
+ my_nid);
if (rc != NPE_SUCCESS) {
test->state = TEST_ERROR;
test->err_rc = rc;
@@ -1996,10 +2029,10 @@
}
server = find_server_in_hash(test->server_id);
xmlSetProp(cmd,(const xmlChar *)"tid", test->id);
- rc = send_control_message(server->sock,
- cmd,
- server->id,
- my_nid);
+ rc = write_to_control_connection(server->source,
+ cmd,
+ server->id,
+ my_nid);
if (rc != NPE_SUCCESS) {
test->state = TEST_ERROR;
test->err_rc = rc;
@@ -2057,10 +2090,10 @@
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);
+ rc = write_to_control_connection(server->source,
+ cmd,
+ server->id,
+ my_nid);
if (rc != NPE_SUCCESS) {
server->state = NSRV_ERROR;
server->err_rc = rc;
Modified: branches/glib_migration/src/netserver.c
===================================================================
--- branches/glib_migration/src/netserver.c 2006-03-24 19:54:33 UTC (rev 97)
+++ branches/glib_migration/src/netserver.c 2006-03-24 22:15:26 UTC (rev 98)
@@ -647,11 +647,14 @@
}
test->state = new;
if (msg) {
- rc = send_control_message(netperf->sock, msg, netperf->id, netperf->my_nid);
+ rc = write_to_control_connection(netperf->source,
+ msg,
+ netperf->id,
+ netperf->my_nid);
if (rc != NPE_SUCCESS) {
if (debug) {
g_fprintf(where,
- "%s: send_control_message failed\n", __func__);
+ "%s: write_to_control_connection failed\n", __func__);
fflush(where);
}
}
More information about the netperf-dev
mailing list