From owner-p4-projects@FreeBSD.ORG Sun Jun 17 11:34:06 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D3BE416A46B; Sun, 17 Jun 2007 11:34:05 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id ABF6A16A468 for ; Sun, 17 Jun 2007 11:34:05 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 9C88913C458 for ; Sun, 17 Jun 2007 11:34:05 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l5HBY514033217 for ; Sun, 17 Jun 2007 11:34:05 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5HBY5I5033193 for perforce@freebsd.org; Sun, 17 Jun 2007 11:34:05 GMT (envelope-from andrew@freebsd.org) Date: Sun, 17 Jun 2007 11:34:05 GMT Message-Id: <200706171134.l5HBY5I5033193@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 121847 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2007 11:34:06 -0000 http://perforce.freebsd.org/chv.cgi?CH=121847 Change 121847 by andrew@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 . 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 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 = ""; + 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, "", name); facund_send(conn, str, strlen(str)); @@ -212,6 +225,7 @@ } else if (strcmp(name, "facund-client") == 0) { snprintf(str, 1024, ""); facund_send(conn, str, strlen(str)); + conn->close = 1; } }