#include "mcreq.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
mc_PIPELINE *pl;
hrtime_t now;
} mc__FLUSHINFO;
static unsigned int
mcreq_flush_iov_fill(mc_PIPELINE *pipeline, nb_IOV *iov, int niov, int *nused)
{
return netbuf_start_flush(&pipeline->nbmgr, iov, niov, nused);
}
static nb_SIZE
mcreq__pktflush_callback(void *p, nb_SIZE hint, void *arg)
{
nb_SIZE pktsize;
mc_PACKET *pkt = (mc_PACKET *)p;
mc__FLUSHINFO *info = (mc__FLUSHINFO *)arg;
pktsize = mcreq_get_size(pkt);
if (info->now && hint) {
MCREQ_PKT_RDATA(pkt)->start = info->now;
}
if (hint < pktsize) {
return pktsize;
}
pkt->flags |= MCREQ_F_FLUSHED;
if (pkt->flags & MCREQ_F_INVOKED) {
mcreq_packet_done(info->pl, pkt);
}
return pktsize;
}
static void
mcreq_flush_done_ex(mc_PIPELINE *pl,
unsigned nflushed, unsigned expected, lcb_U64 now)
{
if (nflushed) {
mc__FLUSHINFO info = { pl, now };
netbuf_end_flush2(&pl->nbmgr, nflushed,
mcreq__pktflush_callback,
offsetof(mc_PACKET, sl_flushq), &info);
}
if (nflushed < expected) {
netbuf_reset_flush(&pl->nbmgr);
}
}
static void
mcreq_flush_done(mc_PIPELINE *pl, unsigned nflushed, unsigned expected)
{
mcreq_flush_done_ex(pl, nflushed, expected, 0);
}
#ifdef __cplusplus
}
#endif