mirror of
https://github.com/tmux/tmux.git
synced 2025-01-12 19:39:04 +00:00
Rename some imsg bits to make namespace collisions less likely buf to
ibuf, buf_read to ibuf_read, READ_BUF_SIZE to IBUF_READ_SIZE. ok henning gilles claudio jacekm deraadt
This commit is contained in:
parent
1e8faaa217
commit
c47d66f49b
@ -28,16 +28,16 @@
|
|||||||
|
|
||||||
#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);
|
||||||
@ -49,15 +49,15 @@ buf_open(size_t len)
|
|||||||
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)
|
||||||
@ -67,7 +67,7 @@ buf_dynamic(size_t len, size_t max)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
buf_realloc(struct buf *buf, size_t len)
|
ibuf_realloc(struct ibuf *buf, size_t len)
|
||||||
{
|
{
|
||||||
u_char *b;
|
u_char *b;
|
||||||
|
|
||||||
@ -87,10 +87,10 @@ buf_realloc(struct buf *buf, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -99,12 +99,12 @@ buf_add(struct buf *buf, const void *data, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -113,7 +113,7 @@ buf_reserve(struct buf *buf, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@ -123,28 +123,28 @@ buf_seek(struct buf *buf, size_t pos, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ buf_write(struct msgbuf *msgbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buf_free(struct buf *buf)
|
ibuf_free(struct ibuf *buf)
|
||||||
{
|
{
|
||||||
free(buf->buf);
|
free(buf->buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -193,14 +193,14 @@ msgbuf_init(struct msgbuf *msgbuf)
|
|||||||
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;
|
||||||
@ -211,17 +211,17 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n)
|
|||||||
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;
|
||||||
@ -284,14 +284,14 @@ msgbuf_write(struct msgbuf *msgbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -299,5 +299,5 @@ buf_dequeue(struct msgbuf *msgbuf, struct buf *buf)
|
|||||||
close(buf->fd);
|
close(buf->fd);
|
||||||
|
|
||||||
msgbuf->queued--;
|
msgbuf->queued--;
|
||||||
buf_free(buf);
|
ibuf_free(buf);
|
||||||
}
|
}
|
||||||
|
20
imsg.c
20
imsg.c
@ -135,7 +135,7 @@ int
|
|||||||
imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
pid_t pid, int fd, void *data, u_int16_t datalen)
|
pid_t pid, int fd, void *data, u_int16_t datalen)
|
||||||
{
|
{
|
||||||
struct buf *wbuf;
|
struct ibuf *wbuf;
|
||||||
|
|
||||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -154,7 +154,7 @@ int
|
|||||||
imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
pid_t pid, int fd, const struct iovec *iov, int iovcnt)
|
pid_t pid, int fd, const struct iovec *iov, int iovcnt)
|
||||||
{
|
{
|
||||||
struct buf *wbuf;
|
struct ibuf *wbuf;
|
||||||
int i, datalen = 0;
|
int i, datalen = 0;
|
||||||
|
|
||||||
for (i = 0; i < iovcnt; i++)
|
for (i = 0; i < iovcnt; i++)
|
||||||
@ -175,11 +175,11 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
struct buf *
|
struct ibuf *
|
||||||
imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||||
pid_t pid, u_int16_t datalen)
|
pid_t pid, u_int16_t datalen)
|
||||||
{
|
{
|
||||||
struct buf *wbuf;
|
struct ibuf *wbuf;
|
||||||
struct imsg_hdr hdr;
|
struct imsg_hdr hdr;
|
||||||
|
|
||||||
datalen += IMSG_HEADER_SIZE;
|
datalen += IMSG_HEADER_SIZE;
|
||||||
@ -193,7 +193,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
|||||||
hdr.peerid = peerid;
|
hdr.peerid = peerid;
|
||||||
if ((hdr.pid = pid) == 0)
|
if ((hdr.pid = pid) == 0)
|
||||||
hdr.pid = ibuf->pid;
|
hdr.pid = ibuf->pid;
|
||||||
if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
||||||
@ -203,18 +203,18 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
imsg_add(struct buf *msg, void *data, u_int16_t datalen)
|
imsg_add(struct ibuf *msg, void *data, u_int16_t datalen)
|
||||||
{
|
{
|
||||||
if (datalen)
|
if (datalen)
|
||||||
if (buf_add(msg, data, datalen) == -1) {
|
if (ibuf_add(msg, data, datalen) == -1) {
|
||||||
buf_free(msg);
|
ibuf_free(msg);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (datalen);
|
return (datalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_close(struct imsgbuf *ibuf, struct buf *msg)
|
imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
||||||
{
|
{
|
||||||
struct imsg_hdr *hdr;
|
struct imsg_hdr *hdr;
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg)
|
|||||||
|
|
||||||
hdr->len = (u_int16_t)msg->wpos;
|
hdr->len = (u_int16_t)msg->wpos;
|
||||||
|
|
||||||
buf_close(&ibuf->w, msg);
|
ibuf_close(&ibuf->w, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
40
imsg.h
40
imsg.h
@ -18,12 +18,12 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define READ_BUF_SIZE 65535
|
#define IBUF_READ_SIZE 65535
|
||||||
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
||||||
#define MAX_IMSGSIZE 16384
|
#define MAX_IMSGSIZE 16384
|
||||||
|
|
||||||
struct buf {
|
struct ibuf {
|
||||||
TAILQ_ENTRY(buf) entry;
|
TAILQ_ENTRY(ibuf) entry;
|
||||||
u_char *buf;
|
u_char *buf;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t max;
|
size_t max;
|
||||||
@ -33,13 +33,13 @@ struct buf {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct msgbuf {
|
struct msgbuf {
|
||||||
TAILQ_HEAD(, buf) bufs;
|
TAILQ_HEAD(, ibuf) bufs;
|
||||||
u_int32_t queued;
|
u_int32_t queued;
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct buf_read {
|
struct ibuf_read {
|
||||||
u_char buf[READ_BUF_SIZE];
|
u_char buf[IBUF_READ_SIZE];
|
||||||
u_char *rptr;
|
u_char *rptr;
|
||||||
size_t wpos;
|
size_t wpos;
|
||||||
};
|
};
|
||||||
@ -51,7 +51,7 @@ struct imsg_fd {
|
|||||||
|
|
||||||
struct imsgbuf {
|
struct imsgbuf {
|
||||||
TAILQ_HEAD(, imsg_fd) fds;
|
TAILQ_HEAD(, imsg_fd) fds;
|
||||||
struct buf_read r;
|
struct ibuf_read r;
|
||||||
struct msgbuf w;
|
struct msgbuf w;
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -75,16 +75,16 @@ struct imsg {
|
|||||||
|
|
||||||
|
|
||||||
/* buffer.c */
|
/* buffer.c */
|
||||||
struct buf *buf_open(size_t);
|
struct ibuf *ibuf_open(size_t);
|
||||||
struct buf *buf_dynamic(size_t, size_t);
|
struct ibuf *ibuf_dynamic(size_t, size_t);
|
||||||
int buf_add(struct buf *, const void *, size_t);
|
int ibuf_add(struct ibuf *, const void *, size_t);
|
||||||
void *buf_reserve(struct buf *, size_t);
|
void *ibuf_reserve(struct ibuf *, size_t);
|
||||||
void *buf_seek(struct buf *, size_t, size_t);
|
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
||||||
size_t buf_size(struct buf *);
|
size_t ibuf_size(struct ibuf *);
|
||||||
size_t buf_left(struct buf *);
|
size_t ibuf_left(struct ibuf *);
|
||||||
void buf_close(struct msgbuf *, struct buf *);
|
void ibuf_close(struct msgbuf *, struct ibuf *);
|
||||||
int buf_write(struct msgbuf *);
|
int ibuf_write(struct msgbuf *);
|
||||||
void buf_free(struct buf *);
|
void ibuf_free(struct ibuf *);
|
||||||
void msgbuf_init(struct msgbuf *);
|
void msgbuf_init(struct msgbuf *);
|
||||||
void msgbuf_clear(struct msgbuf *);
|
void msgbuf_clear(struct msgbuf *);
|
||||||
int msgbuf_write(struct msgbuf *);
|
int msgbuf_write(struct msgbuf *);
|
||||||
@ -98,10 +98,10 @@ int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
|||||||
int, void *, u_int16_t);
|
int, void *, u_int16_t);
|
||||||
int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||||
int, const struct iovec *, int);
|
int, const struct iovec *, int);
|
||||||
struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||||
u_int16_t);
|
u_int16_t);
|
||||||
int imsg_add(struct buf *, void *, u_int16_t);
|
int imsg_add(struct ibuf *, void *, u_int16_t);
|
||||||
void imsg_close(struct imsgbuf *, struct buf *);
|
void imsg_close(struct imsgbuf *, struct ibuf *);
|
||||||
void imsg_free(struct imsg *);
|
void imsg_free(struct imsg *);
|
||||||
int imsg_flush(struct imsgbuf *);
|
int imsg_flush(struct imsgbuf *);
|
||||||
void imsg_clear(struct imsgbuf *);
|
void imsg_clear(struct imsgbuf *);
|
||||||
|
Loading…
Reference in New Issue
Block a user