PERFORCE change 121847 for review
Andrew Turner
andrew at FreeBSD.org
Sun Jun 17 11:34:06 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=121847
Change 121847 by andrew at andrew_hermies on 2007/06/17 11:33:57
Use calloc rather than malloc/memset
When the back end receives the close of the facund-client element set the connection to be closed. This fixes a bug where the connection would never be closed.
If the backend sends a ping call respond with a <pong/>. This is just for testing and will be removed when calls are implemented properly.
Use the correct values for the call name and ID
Ignore the <facund-client> for now. It will be used later to find the supported version of the protocol.
Affected files ...
.. //depot/projects/soc2007/andrew-update/lib/facund_connection.c#3 edit
.. //depot/projects/soc2007/andrew-update/lib/facund_private.h#4 edit
.. //depot/projects/soc2007/andrew-update/lib/facund_server.c#5 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/lib/facund_connection.c#3 (text+ko) ====
@@ -49,13 +49,11 @@
{
struct facund_conn *conn;
- conn = malloc(sizeof(struct facund_conn));
+ conn = calloc(1, sizeof(struct facund_conn));
if (conn == NULL) {
return NULL;
}
- memset(conn, 0, sizeof(struct facund_conn));
-
conn->do_unlink = 0;
conn->local.sun_family = AF_LOCAL;
==== //depot/projects/soc2007/andrew-update/lib/facund_private.h#4 (text+ko) ====
@@ -59,6 +59,8 @@
socklen_t sock_len; /* sizeof(remote) */
int sock; /* The socket fd */
int fd; /* The fd to the remote device */
+ int close; /* True when we should
+ * close the connection */
XML_Parser parser;
char current_call[32];
==== //depot/projects/soc2007/andrew-update/lib/facund_server.c#5 (text+ko) ====
@@ -80,6 +80,10 @@
char *buf;
ssize_t len;
+ if (conn->close == 1) {
+ return 1;
+ }
+
buf = XML_GetBuffer(conn->parser, BUF_SIZE);
if (buf == NULL)
return -1;
@@ -110,8 +114,15 @@
}
static void
-facund_server_call(struct facund_conn *conn __unused, const char *name, const char *id, struct facund_object *arg)
+facund_server_call(struct facund_conn *conn, const char *name, const char *id,
+ struct facund_object *arg)
{
+ /* This is not really a valid command. It is just used for testing */
+ if (strcmp(name, "ping") == 0) {
+ const char *msg = "<pong/>";
+ facund_send(conn, msg, strlen(msg));
+ return;
+ }
printf("Call: %s\nID: %s\nArg:\n", name, id);
facund_object_print(arg);
putchar('\n');
@@ -141,13 +152,13 @@
/* TODO: Return an error */
return;
}
- call_name = attrs[i];
+ call_name = attrs[i + 1];
} else if (strcmp(attrs[i], "id") == 0) {
if (id != NULL) {
/* TODO: Return an error */
return;
}
- id = attrs[i];
+ id = attrs[i + 1];
} else {
/* TODO: Return an error */
return;
@@ -179,6 +190,8 @@
facund_object_array_append(conn->call_arg, obj);
}
conn->call_arg = obj;
+ } else if (strcmp(name, "facund-client") == 0) {
+ /* Pass */
} else {
snprintf(str, 1024, "<unknown element=\"%s\"/>", name);
facund_send(conn, str, strlen(str));
@@ -212,6 +225,7 @@
} else if (strcmp(name, "facund-client") == 0) {
snprintf(str, 1024, "</facund-server>");
facund_send(conn, str, strlen(str));
+ conn->close = 1;
}
}
More information about the p4-projects
mailing list