The flush filter method is called when buffered data should be sent. Filters that buffer outgoing data should implement the flush filter method.
Upon receiving control, a flush implementation must write any buffered data to the filter layer immediately below it. Before returning success, a flush implementation must successfully call the net_flush function:
net_flush(layer->lower).
int flush(FilterLayer *layer);
0 on success or -1 if an error occurred.
FilterLayer *layer is the filter layer the filter is installed in.
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); }