[BACK]Return to imsg-buffer.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/Attic/imsg-buffer.c between version 1.2 and 1.3

version 1.2, 2009/09/15 18:12:51 version 1.3, 2010/05/26 13:56:07
Line 28 
Line 28 
   
 #include "imsg.h"  #include "imsg.h"
   
 int     buf_realloc(struct buf *, size_t);  int     ibuf_realloc(struct ibuf *, size_t);
 void    buf_enqueue(struct msgbuf *, struct buf *);  void    ibuf_enqueue(struct msgbuf *, struct ibuf *);
 void    buf_dequeue(struct msgbuf *, struct buf *);  void    ibuf_dequeue(struct msgbuf *, struct ibuf *);
   
 struct buf *  struct ibuf *
 buf_open(size_t len)  ibuf_open(size_t len)
 {  {
         struct buf      *buf;          struct ibuf     *buf;
   
         if ((buf = calloc(1, sizeof(struct buf))) == NULL)          if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
                 return (NULL);                  return (NULL);
         if ((buf->buf = malloc(len)) == NULL) {          if ((buf->buf = malloc(len)) == NULL) {
                 free(buf);                  free(buf);
Line 49 
Line 49 
         return (buf);          return (buf);
 }  }
   
 struct buf *  struct ibuf *
 buf_dynamic(size_t len, size_t max)  ibuf_dynamic(size_t len, size_t max)
 {  {
         struct buf      *buf;          struct ibuf     *buf;
   
         if (max < len)          if (max < len)
                 return (NULL);                  return (NULL);
   
         if ((buf = buf_open(len)) == NULL)          if ((buf = ibuf_open(len)) == NULL)
                 return (NULL);                  return (NULL);
   
         if (max > 0)          if (max > 0)
Line 67 
Line 67 
 }  }
   
 int  int
 buf_realloc(struct buf *buf, size_t len)  ibuf_realloc(struct ibuf *buf, size_t len)
 {  {
         u_char  *b;          u_char  *b;
   
Line 87 
Line 87 
 }  }
   
 int  int
 buf_add(struct buf *buf, const void *data, size_t len)  ibuf_add(struct ibuf *buf, const void *data, size_t len)
 {  {
         if (buf->wpos + len > buf->size)          if (buf->wpos + len > buf->size)
                 if (buf_realloc(buf, len) == -1)                  if (ibuf_realloc(buf, len) == -1)
                         return (-1);                          return (-1);
   
         memcpy(buf->buf + buf->wpos, data, len);          memcpy(buf->buf + buf->wpos, data, len);
Line 99 
Line 99 
 }  }
   
 void *  void *
 buf_reserve(struct buf *buf, size_t len)  ibuf_reserve(struct ibuf *buf, size_t len)
 {  {
         void    *b;          void    *b;
   
         if (buf->wpos + len > buf->size)          if (buf->wpos + len > buf->size)
                 if (buf_realloc(buf, len) == -1)                  if (ibuf_realloc(buf, len) == -1)
                         return (NULL);                          return (NULL);
   
         b = buf->buf + buf->wpos;          b = buf->buf + buf->wpos;
Line 113 
Line 113 
 }  }
   
 void *  void *
 buf_seek(struct buf *buf, size_t pos, size_t len)  ibuf_seek(struct ibuf *buf, size_t pos, size_t len)
 {  {
         /* only allowed to seek in already written parts */          /* only allowed to seek in already written parts */
         if (pos + len > buf->wpos)          if (pos + len > buf->wpos)
Line 123 
Line 123 
 }  }
   
 size_t  size_t
 buf_size(struct buf *buf)  ibuf_size(struct ibuf *buf)
 {  {
         return (buf->wpos);          return (buf->wpos);
 }  }
   
 size_t  size_t
 buf_left(struct buf *buf)  ibuf_left(struct ibuf *buf)
 {  {
         return (buf->max - buf->wpos);          return (buf->max - buf->wpos);
 }  }
   
 void  void
 buf_close(struct msgbuf *msgbuf, struct buf *buf)  ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf)
 {  {
         buf_enqueue(msgbuf, buf);          ibuf_enqueue(msgbuf, buf);
 }  }
   
 int  int
 buf_write(struct msgbuf *msgbuf)  ibuf_write(struct msgbuf *msgbuf)
 {  {
         struct iovec     iov[IOV_MAX];          struct iovec     iov[IOV_MAX];
         struct buf      *buf;          struct ibuf     *buf;
         unsigned int     i = 0;          unsigned int     i = 0;
         ssize_t n;          ssize_t n;
   
Line 176 
Line 176 
 }  }
   
 void  void
 buf_free(struct buf *buf)  ibuf_free(struct ibuf *buf)
 {  {
         free(buf->buf);          free(buf->buf);
         free(buf);          free(buf);
Line 193 
Line 193 
 void  void
 msgbuf_drain(struct msgbuf *msgbuf, size_t n)  msgbuf_drain(struct msgbuf *msgbuf, size_t n)
 {  {
         struct buf      *buf, *next;          struct ibuf     *buf, *next;
   
         for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;          for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
             buf = next) {              buf = next) {
                 next = TAILQ_NEXT(buf, entry);                  next = TAILQ_NEXT(buf, entry);
                 if (buf->rpos + n >= buf->wpos) {                  if (buf->rpos + n >= buf->wpos) {
                         n -= buf->wpos - buf->rpos;                          n -= buf->wpos - buf->rpos;
                         buf_dequeue(msgbuf, buf);                          ibuf_dequeue(msgbuf, buf);
                 } else {                  } else {
                         buf->rpos += n;                          buf->rpos += n;
                         n = 0;                          n = 0;
Line 211 
Line 211 
 void  void
 msgbuf_clear(struct msgbuf *msgbuf)  msgbuf_clear(struct msgbuf *msgbuf)
 {  {
         struct buf      *buf;          struct ibuf     *buf;
   
         while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)          while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)
                 buf_dequeue(msgbuf, buf);                  ibuf_dequeue(msgbuf, buf);
 }  }
   
 int  int
 msgbuf_write(struct msgbuf *msgbuf)  msgbuf_write(struct msgbuf *msgbuf)
 {  {
         struct iovec     iov[IOV_MAX];          struct iovec     iov[IOV_MAX];
         struct buf      *buf;          struct ibuf     *buf;
         unsigned int     i = 0;          unsigned int     i = 0;
         ssize_t          n;          ssize_t          n;
         struct msghdr    msg;          struct msghdr    msg;
Line 284 
Line 284 
 }  }
   
 void  void
 buf_enqueue(struct msgbuf *msgbuf, struct buf *buf)  ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
 {  {
         TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);          TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
         msgbuf->queued++;          msgbuf->queued++;
 }  }
   
 void  void
 buf_dequeue(struct msgbuf *msgbuf, struct buf *buf)  ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
 {  {
         TAILQ_REMOVE(&msgbuf->bufs, buf, entry);          TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
   
Line 299 
Line 299 
                 close(buf->fd);                  close(buf->fd);
   
         msgbuf->queued--;          msgbuf->queued--;
         buf_free(buf);          ibuf_free(buf);
 }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3