Tweaked the msg_list code so that the head and tail pointers
authorWayne Davison <wayned@samba.org>
Thu, 8 Dec 2005 21:01:38 +0000 (21:01 +0000)
committerWayne Davison <wayned@samba.org>
Thu, 8 Dec 2005 21:01:38 +0000 (21:01 +0000)
are contained by a structure.

io.c

diff --git a/io.c b/io.c
index 439f717..b9668af 100644 (file)
--- a/io.c
+++ b/io.c
@@ -119,14 +119,17 @@ struct flist_ndx_list {
 
 static struct flist_ndx_list redo_list, hlink_list;
 
 
 static struct flist_ndx_list redo_list, hlink_list;
 
-struct msg_list {
-       struct msg_list *next;
+struct msg_list_item {
+       struct msg_list_item *next;
        char *buf;
        int len;
 };
 
        char *buf;
        int len;
 };
 
-static struct msg_list *msg_list_head;
-static struct msg_list *msg_list_tail;
+struct msg_list {
+       struct msg_list_item *head, *tail;
+};
+
+static struct msg_list msg_list;
 
 static void flist_ndx_push(struct flist_ndx_list *lp, int ndx)
 {
 
 static void flist_ndx_push(struct flist_ndx_list *lp, int ndx)
 {
@@ -224,9 +227,9 @@ void set_msg_fd_out(int fd)
 /* Add a message to the pending MSG_* list. */
 static void msg_list_add(int code, char *buf, int len)
 {
 /* Add a message to the pending MSG_* list. */
 static void msg_list_add(int code, char *buf, int len)
 {
-       struct msg_list *ml;
+       struct msg_list_item *ml;
 
 
-       if (!(ml = new(struct msg_list)))
+       if (!(ml = new(struct msg_list_item)))
                out_of_memory("msg_list_add");
        ml->next = NULL;
        if (!(ml->buf = new_array(char, len+4)))
                out_of_memory("msg_list_add");
        ml->next = NULL;
        if (!(ml->buf = new_array(char, len+4)))
@@ -234,11 +237,11 @@ static void msg_list_add(int code, char *buf, int len)
        SIVAL(ml->buf, 0, ((code+MPLEX_BASE)<<24) | len);
        memcpy(ml->buf+4, buf, len);
        ml->len = len+4;
        SIVAL(ml->buf, 0, ((code+MPLEX_BASE)<<24) | len);
        memcpy(ml->buf+4, buf, len);
        ml->len = len+4;
-       if (msg_list_tail)
-               msg_list_tail->next = ml;
+       if (msg_list.tail)
+               msg_list.tail->next = ml;
        else
        else
-               msg_list_head = ml;
-       msg_list_tail = ml;
+               msg_list.head = ml;
+       msg_list.tail = ml;
 }
 
 void send_msg(enum msgcode code, char *buf, int len)
 }
 
 void send_msg(enum msgcode code, char *buf, int len)
@@ -339,8 +342,8 @@ int msg_list_push(int flush_it_all)
        if (msg_fd_out < 0)
                return -1;
 
        if (msg_fd_out < 0)
                return -1;
 
-       while (msg_list_head) {
-               struct msg_list *ml = msg_list_head;
+       while (msg_list.head) {
+               struct msg_list_item *ml = msg_list.head;
                int n = write(msg_fd_out, ml->buf + written, ml->len - written);
                if (n < 0) {
                        if (errno == EINTR)
                int n = write(msg_fd_out, ml->buf + written, ml->len - written);
                if (n < 0) {
                        if (errno == EINTR)
@@ -357,9 +360,9 @@ int msg_list_push(int flush_it_all)
                                check_timeout();
                } else if ((written += n) == ml->len) {
                        free(ml->buf);
                                check_timeout();
                } else if ((written += n) == ml->len) {
                        free(ml->buf);
-                       msg_list_head = ml->next;
-                       if (!msg_list_head)
-                               msg_list_tail = NULL;
+                       msg_list.head = ml->next;
+                       if (!msg_list.head)
+                               msg_list.tail = NULL;
                        free(ml);
                        written = 0;
                }
                        free(ml);
                        written = 0;
                }
@@ -462,7 +465,7 @@ static int read_timeout(int fd, char *buf, size_t len)
                FD_ZERO(&r_fds);
                FD_ZERO(&w_fds);
                FD_SET(fd, &r_fds);
                FD_ZERO(&r_fds);
                FD_ZERO(&w_fds);
                FD_SET(fd, &r_fds);
-               if (msg_list_head) {
+               if (msg_list.head) {
                        FD_SET(msg_fd_out, &w_fds);
                        if (msg_fd_out > maxfd)
                                maxfd = msg_fd_out;
                        FD_SET(msg_fd_out, &w_fds);
                        if (msg_fd_out > maxfd)
                                maxfd = msg_fd_out;
@@ -499,7 +502,7 @@ static int read_timeout(int fd, char *buf, size_t len)
                        continue;
                }
 
                        continue;
                }
 
-               if (msg_list_head && FD_ISSET(msg_fd_out, &w_fds))
+               if (msg_list.head && FD_ISSET(msg_fd_out, &w_fds))
                        msg_list_push(NORMAL_FLUSH);
 
                if (io_filesfrom_f_out >= 0) {
                        msg_list_push(NORMAL_FLUSH);
 
                if (io_filesfrom_f_out >= 0) {