Tweaked the msg_list code so that the head and tail pointers

are contained by a structure.
This commit is contained in:
Wayne Davison
2005-12-08 21:01:38 +00:00
parent 0fb2fc4a1d
commit 08c88178aa

37
io.c
View File

@@ -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_item {
struct msg_list *next; struct msg_list_item *next;
char *buf; char *buf;
int len; int len;
}; };
static struct msg_list *msg_list_head; struct msg_list {
static struct msg_list *msg_list_tail; 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. */ /* Add a message to the pending MSG_* list. */
static void msg_list_add(int code, char *buf, int len) 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"); out_of_memory("msg_list_add");
ml->next = NULL; ml->next = NULL;
if (!(ml->buf = new_array(char, len+4))) 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); SIVAL(ml->buf, 0, ((code+MPLEX_BASE)<<24) | len);
memcpy(ml->buf+4, buf, len); memcpy(ml->buf+4, buf, len);
ml->len = len+4; ml->len = len+4;
if (msg_list_tail) if (msg_list.tail)
msg_list_tail->next = ml; msg_list.tail->next = ml;
else else
msg_list_head = ml; msg_list.head = ml;
msg_list_tail = 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) if (msg_fd_out < 0)
return -1; return -1;
while (msg_list_head) { while (msg_list.head) {
struct msg_list *ml = msg_list_head; struct msg_list_item *ml = msg_list.head;
int n = write(msg_fd_out, ml->buf + written, ml->len - written); int n = write(msg_fd_out, ml->buf + written, ml->len - written);
if (n < 0) { if (n < 0) {
if (errno == EINTR) if (errno == EINTR)
@@ -357,9 +360,9 @@ int msg_list_push(int flush_it_all)
check_timeout(); check_timeout();
} else if ((written += n) == ml->len) { } else if ((written += n) == ml->len) {
free(ml->buf); free(ml->buf);
msg_list_head = ml->next; msg_list.head = ml->next;
if (!msg_list_head) if (!msg_list.head)
msg_list_tail = NULL; msg_list.tail = NULL;
free(ml); free(ml);
written = 0; written = 0;
} }
@@ -462,7 +465,7 @@ static int read_timeout(int fd, char *buf, size_t len)
FD_ZERO(&r_fds); FD_ZERO(&r_fds);
FD_ZERO(&w_fds); FD_ZERO(&w_fds);
FD_SET(fd, &r_fds); FD_SET(fd, &r_fds);
if (msg_list_head) { if (msg_list.head) {
FD_SET(msg_fd_out, &w_fds); FD_SET(msg_fd_out, &w_fds);
if (msg_fd_out > maxfd) if (msg_fd_out > maxfd)
maxfd = msg_fd_out; 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); msg_list_push(NORMAL_FLUSH);
if (io_filesfrom_f_out >= 0) { if (io_filesfrom_f_out >= 0) {