int myfilter_flush(FilterLayer *layer) { MyFilterContext context = (MyFilterContext *)layer->context->data; if (context->buf.count) { int rv; rv = net_write(layer->lower, context->buf.data, context->buf.count); if (rv != context->buf.count) return -1; /* failed to flush data */ context->buf.count = 0; } return net_flush(layer->lower); }