static int tcp_subparser_ctor(struct tcp_subparser *tcp_sub, struct mux_parser *mux_parser, struct parser *child, struct proto *requestor, struct port_key const *key, struct timeval const *now) { SLOG(LOG_DEBUG, "Constructing TCP subparser @%p", tcp_sub); CHECK_LAST_FIELD(tcp_subparser, mux_subparser, struct mux_subparser); tcp_sub->fin = 0; tcp_sub->ack = 0; tcp_sub->syn = 0; tcp_sub->origin = 0; tcp_sub->srv_set = 0; // will be set later if (0 != pkt_wait_list_ctor(tcp_sub->wl+0, 0 /* relative to the ISN */, &tcp_wl_config, child, tcp_sub->wl+1)) { return -1; } if (0 != pkt_wait_list_ctor(tcp_sub->wl+1, 0 /* relative to the ISN */, &tcp_wl_config, child, tcp_sub->wl+0)) { pkt_wait_list_dtor(tcp_sub->wl+0); return -1; } tcp_sub->mutex = mutex_pool_anyone(&tcp_locks); // Now that everything is ready, make this subparser public if (0 != mux_subparser_ctor(&tcp_sub->mux_subparser, mux_parser, child, requestor, key, now)) { pkt_wait_list_dtor(tcp_sub->wl+0); pkt_wait_list_dtor(tcp_sub->wl+1); return -1; } return 0; }
int streambuf_ctor(struct streambuf *sbuf, parse_fun *parse, size_t max_size, struct mutex_pool *pool) { SLOG(LOG_DEBUG, "Constructing a streambuf@%p of max size %zu", sbuf, max_size); sbuf->parse = parse; sbuf->max_size = max_size; sbuf->mutex = mutex_pool_anyone(pool ? pool : &streambuf_locks); for (unsigned d = 0; d < 2; d++) { sbuf->dir[d].buffer = NULL; sbuf->dir[d].buffer_size = 0; sbuf->dir[d].restart_offset = 0; } return 0; }