Use ibuf_fd_get/set/avail in the file descriptor passing code.
Switch some ibuf_seek() calls to ibuf_set() and use ibuf_add_zero() instead
of ibuf_reserve().
OK tb@ job@
-/* $OpenBSD: http.c,v 1.76 2023/06/12 15:27:52 claudio Exp $ */
+/* $OpenBSD: http.c,v 1.77 2023/06/20 15:15:14 claudio Exp $ */
/*
* Copyright (c) 2020 Nils Fisher <nils_fisher@hotmail.com>
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
io_read_str(b, &mod);
/* queue up new requests */
- http_req_new(id, uri, mod, 0, b->fd);
+ http_req_new(id, uri, mod, 0, ibuf_fd_get(b));
ibuf_free(b);
}
}
-/* $OpenBSD: io.c,v 1.22 2022/12/14 15:19:16 claudio Exp $ */
+/* $OpenBSD: io.c,v 1.23 2023/06/20 15:15:14 claudio Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
if ((b = ibuf_dynamic(64, INT32_MAX)) == NULL)
err(1, NULL);
- ibuf_reserve(b, sizeof(size_t)); /* can not fail */
+ ibuf_add_zero(b, sizeof(size_t)); /* can not fail */
return b;
}
size_t len;
len = ibuf_size(b) - sizeof(len);
- memcpy(ibuf_seek(b, 0, sizeof(len)), &len, sizeof(len));
+ ibuf_set(b, 0, &len, sizeof(len));
ibuf_close(msgbuf, b);
}
for (i = 0; i < j; i++) {
f = ((int *)CMSG_DATA(cmsg))[i];
if (i == 0)
- b->fd = f;
+ ibuf_fd_set(b, f);
else
close(f);
}
-/* $OpenBSD: main.c,v 1.241 2023/05/30 16:02:28 job Exp $ */
+/* $OpenBSD: main.c,v 1.242 2023/06/20 15:15:14 claudio Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
io_str_buffer(b, uri);
io_str_buffer(b, last_mod);
/* pass file as fd */
- b->fd = fd;
+ ibuf_fd_set(b, fd);
io_close_buffer(&httpq, b);
}
b = io_new_buffer();
io_simple_buffer(b, &type, sizeof(type));
io_simple_buffer(b, &id, sizeof(id));
- b->fd = pi[0];
+ ibuf_fd_set(b, pi[0]);
io_close_buffer(&rrdpq, b);
http_fetch(id, uri, last_mod, pi[1]);
-/* $OpenBSD: rrdp.c,v 1.30 2023/05/03 07:51:08 claudio Exp $ */
+/* $OpenBSD: rrdp.c,v 1.31 2023/06/20 15:15:14 claudio Exp $ */
/*
* Copyright (c) 2020 Nils Fisher <nils_fisher@hotmail.com>
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
io_read_str(b, &session_id);
io_read_buf(b, &serial, sizeof(serial));
io_read_str(b, &last_mod);
- if (b->fd != -1)
+ if (ibuf_fd_avail(b))
errx(1, "received unexpected fd");
rrdp_new(id, local, notify, session_id, serial, last_mod);
break;
case RRDP_HTTP_INI:
- if (b->fd == -1)
- errx(1, "expected fd not received");
s = rrdp_get(id);
if (s == NULL)
errx(1, "http ini, rrdp session %u does not exist", id);
if (s->state != RRDP_STATE_WAIT)
errx(1, "%s: bad internal state", s->local);
- s->infd = b->fd;
+ s->infd = ibuf_fd_get(b);
+ if (s->infd == -1)
+ errx(1, "expected fd not received");
s->state = RRDP_STATE_PARSE;
if (s->aborted) {
rrdp_abort_req(s);
case RRDP_HTTP_FIN:
io_read_buf(b, &res, sizeof(res));
io_read_str(b, &last_mod);
- if (b->fd != -1)
+ if (ibuf_fd_avail(b))
errx(1, "received unexpected fd");
s = rrdp_get(id);
s = rrdp_get(id);
if (s == NULL)
errx(1, "file, rrdp session %u does not exist", id);;
- if (b->fd != -1)
+ if (ibuf_fd_avail(b))
errx(1, "received unexpected fd");
io_read_buf(b, &ok, sizeof(ok));
if (ok != 1)
rrdp_finished(s);
break;
case RRDP_ABORT:
- if (b->fd != -1)
+ if (ibuf_fd_avail(b))
errx(1, "received unexpected fd");
s = rrdp_get(id);
if (s != NULL)