#include "buf.h"
#include "compiler.h"
#include "fdflags.h"
+#include "growbuf.h"
#include "lbuf.h"
#include "mdup.h"
#include "quis.h"
static void init_comms(struct tvec_remotecomms *rc)
{
- rc->bin = 0; rc->binsz = 0; dbuf_create(&rc->bout);
+ rc->bin = 0; rc->binsz = 0; DBCREATE(&rc->bout);
rc->infd = rc->outfd = -1; rc->f = 0;
}
*/
static void release_comms(struct tvec_remotecomms *rc)
- { close_comms(rc); xfree(rc->bin); dbuf_destroy(&rc->bout); }
+ { close_comms(rc); xfree(rc->bin); DBDESTROY(&rc->bout); }
/* --- @setup_comms@ --- *
*
if (rc->binlen - rc->binoff >= want) return (RECV_OK);
/* If the buffer is too small then we must grow it. */
- if (want > rc->binsz) {
- sz = rc->binsz; if (!sz) sz = RECVBUFSZ;
- while (sz < want) { assert(sz < (size_t)-1/2); sz *= 2; }
- if (!rc->bin) rc->bin = xmalloc(sz);
- else rc->bin = xrealloc(rc->bin, sz, rc->binsz);
- rc->binsz = sz;
- }
+ GROWBUF_EXTEND(&arena_stdlib, rc->bin, rc->binsz, want, RECVBUFSZ, 1);
/* Shunt the unused existing material to the start of the buffer. */
memmove(rc->bin, rc->bin + rc->binoff, rc->binlen - rc->binoff);
if (vd->regsz <= sizeof(rbuf))
r = &rbuf;
else {
- if (rsz < vd->regsz) {
- xfree(r_alloc);
- if (!rsz) rsz = 8*sizeof(void *);
- while (rsz < vd->regsz) rsz *= 2;
- r_alloc = xmalloc(rsz);
- }
+ GROWBUF_REPLACE(&arena_stdlib, r_alloc, rsz, vd->regsz,
+ 8*sizeof(void *), 1);
r = r_alloc;
}