static void sk_handle_set_frozen(Socket s, int is_frozen) { Handle_Socket ps = (Handle_Socket) s; if (is_frozen) { switch (ps->frozen) { case FREEZING: case FROZEN: return; /* nothing to do */ case THAWING: /* * We were in the middle of emptying our bufchain, and got * frozen again. In that case, winhandl.c is already * throttled, so just return to FROZEN state. The toplevel * callback will notice and disable itself. */ ps->frozen = FROZEN; break; case UNFROZEN: /* * The normal case. Go to FREEZING, and expect one more * load of data from winhandl if we're unlucky. */ ps->frozen = FREEZING; break; } } else { switch (ps->frozen) { case UNFROZEN: case THAWING: return; /* nothing to do */ case FREEZING: /* * If winhandl didn't send us any data throughout the time * we were frozen, then we'll still be in this state and * can just unfreeze in the trivial way. */ assert(bufchain_size(&ps->inputdata) == 0); ps->frozen = UNFROZEN; break; case FROZEN: /* * If we have buffered data, go to THAWING and start * releasing it in top-level callbacks. */ ps->frozen = THAWING; queue_toplevel_callback(handle_socket_unfreeze, ps); } } }
static void handle_socket_unfreeze(void *psv) { Handle_Socket ps = (Handle_Socket) psv; void *data; int len; /* * If we've been put into a state other than THAWING since the * last callback, then we're done. */ if (ps->frozen != THAWING) return; /* * Get some of the data we've buffered. */ bufchain_prefix(&ps->inputdata, &data, &len); assert(len > 0); /* * Hand it off to the plug. Be careful of re-entrance - that might * have the effect of trying to close this socket. */ ps->defer_close = TRUE; plug_receive(ps->plug, 0, data, len); bufchain_consume(&ps->inputdata, len); ps->defer_close = FALSE; if (ps->deferred_close) { sk_handle_close(ps); return; } if (bufchain_size(&ps->inputdata) > 0) { /* * If there's still data in our buffer, stay in THAWING state, * and reschedule ourself. */ queue_toplevel_callback(handle_socket_unfreeze, ps); } else { /* * Otherwise, we've successfully thawed! */ ps->frozen = UNFROZEN; handle_unthrottle(ps->recv_h, 0); } }
static void handle_socket_unfreeze(void *psv) { Handle_Socket ps = (Handle_Socket) psv; void *data; int len, new_backlog; /* * If we've been put into a state other than THAWING since the * last callback, then we're done. */ if (ps->frozen != THAWING) return; /* * Get some of the data we've buffered. */ bufchain_prefix(&ps->inputdata, &data, &len); assert(len > 0); /* * Hand it off to the plug. */ new_backlog = plug_receive(ps->plug, 0, data, len); if (bufchain_size(&ps->inputdata) > 0) { /* * If there's still data in our buffer, stay in THAWING state, * and reschedule ourself. */ queue_toplevel_callback(handle_socket_unfreeze, ps); } else { /* * Otherwise, we've successfully thawed! */ ps->frozen = UNFROZEN; handle_unthrottle(ps->recv_h, new_backlog); } }