server: malloc/free fix
[fio.git] / client.c
index c080c17d03fadaf36466398bb7c062c0bb15b5d0..05bba38d60d54d1a8f9facb7433da41ab07d0a7c 100644 (file)
--- a/client.c
+++ b/client.c
@@ -61,6 +61,7 @@ static struct fio_client *find_client_by_name(const char *name)
 
 static void remove_client(struct fio_client *client)
 {
+       dprint(FD_NET, "removed client <%s>\n", client->hostname);
        flist_del(&client->list);
        nr_clients--;
        free(client->hostname);
@@ -71,6 +72,7 @@ void fio_client_add(const char *hostname)
 {
        struct fio_client *client;
 
+       dprint(FD_NET, "added client <%s>\n", hostname);
        client = malloc(sizeof(*client));
        memset(client, 0, sizeof(*client));
        client->hostname = strdup(hostname);
@@ -83,6 +85,8 @@ static int fio_client_connect(struct fio_client *client)
 {
        int fd;
 
+       dprint(FD_NET, "connect to host %s\n", client->hostname);
+
        memset(&client->addr, 0, sizeof(client->addr));
        client->addr.sin_family = AF_INET;
        client->addr.sin_port = htons(fio_net_port);
@@ -102,13 +106,11 @@ static int fio_client_connect(struct fio_client *client)
        fd = socket(AF_INET, SOCK_STREAM, 0);
        if (fd < 0) {
                log_err("fio: socket: %s\n", strerror(errno));
-               free(client);
                return 1;
        }
 
        if (connect(fd, (struct sockaddr *) &client->addr, sizeof(client->addr)) < 0) {
                log_err("fio: connect: %s\n", strerror(errno));
-               free(client);
                return 1;
        }
 
@@ -149,6 +151,8 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename)
        off_t len;
        int fd, ret;
 
+       dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname);
+
        fd = open(filename, O_RDONLY);
        if (fd < 0) {
                log_err("fio: job file open: %s\n", strerror(errno));
@@ -203,6 +207,9 @@ static int handle_client(struct fio_client *client)
        struct fio_net_cmd *cmd;
 
        while ((cmd = fio_net_cmd_read(client->fd)) != NULL) {
+               dprint(FD_NET, "%s: got cmd op %d\n", client->hostname,
+                                                       cmd->opcode);
+
                if (cmd->opcode == FIO_NET_CMD_ACK) {
                        free(cmd);
                        continue;
@@ -269,6 +276,5 @@ int fio_handle_clients(void)
        }
 
        free(pfds);
-
        return 0;
 }