client: send confirmation messages for ring add/remove
[project/udebug.git] / client.c
index 1fc90d8496cf10f79f36d7435c4cf81401d4c4bf..e75883280ea6101f5a836e89b25f708f93c403ab 100644 (file)
--- a/client.c
+++ b/client.c
@@ -170,6 +170,7 @@ static void client_parse_message(struct client *cl)
        switch (msg->type) {
        case CL_MSG_RING_ADD:
                client_ring_alloc(cl);
+               client_send_msg(cl, msg, -1);
                break;
        case CL_MSG_RING_REMOVE:
                DC(2, cl, "delete ring %x", msg->id);
@@ -178,6 +179,7 @@ static void client_parse_message(struct client *cl)
                        client_ring_free(r);
                else
                        DC(2, cl, "ring not found");
+               client_send_msg(cl, msg, -1);
                break;
        case CL_MSG_RING_NOTIFY:
                DC(3, cl, "notify on ring %d", msg->id);
@@ -199,6 +201,12 @@ static void client_parse_message(struct client *cl)
                DC(3, cl, "Invalid message type %d", msg->type);
                break;
        }
+
+       if (cl->rx_fd < 0)
+               return;
+
+       close(cl->rx_fd);
+       cl->rx_fd = -1;
 }
 
 static void client_fd_cb(struct uloop_fd *fd, unsigned int events)
@@ -224,12 +232,13 @@ static void client_fd_cb(struct uloop_fd *fd, unsigned int events)
        pfd = (int *)CMSG_DATA(cmsg);
        msg.msg_controllen = cmsg->cmsg_len;
 
+retry:
+       *pfd = -1;
        if (fd->eof) {
                client_free(cl);
                return;
        }
 
-retry:
        iov.iov_base = &cl->rx_buf;
        iov.iov_len = min_sz;
        if (!cl->rx_ofs) {
@@ -239,6 +248,8 @@ retry:
                len = recvmsg(fd->fd, &msg, 0);
                if (len < 0)
                        return;
+               if (!len)
+                       fd->eof = true;
 
                cl->rx_ofs = len;
                cl->rx_fd = *pfd;