Beispiel #1
0
/*
 * Call this when proxy negotiation is complete, so that this
 * socket can begin working normally.
 */
void proxy_activate(Proxy_Socket p)
{
  void *data;
  int len;
  long output_before, output_after;

  p->state = PROXY_STATE_ACTIVE;

  /* we want to ignore new receive events until we have sent
   * all of our buffered receive data.
   */
  sk_set_frozen(p->sub_socket, 1);

  /* how many bytes of output have we buffered? */
  output_before = bufchain_size(&p->pending_oob_output_data) +
                  bufchain_size(&p->pending_output_data);
  /* and keep track of how many bytes do not get sent. */
  output_after = 0;

  /* send buffered OOB writes */
  while (bufchain_size(&p->pending_oob_output_data) > 0) {
    bufchain_prefix(&p->pending_oob_output_data, &data, &len);
    output_after += sk_write_oob(p->sub_socket, data, len);
    bufchain_consume(&p->pending_oob_output_data, len);
  }

  /* send buffered normal writes */
  while (bufchain_size(&p->pending_output_data) > 0) {
    bufchain_prefix(&p->pending_output_data, &data, &len);
    output_after += sk_write(p->sub_socket, data, len);
    bufchain_consume(&p->pending_output_data, len);
  }

  /* if we managed to send any data, let the higher levels know. */
  if (output_after < output_before)
    plug_sent(p->plug, output_after);

  /* if we were asked to flush the output during
   * the proxy negotiation process, do so now.
   */
  if (p->pending_flush)
    sk_flush(p->sub_socket);

  /* if we have a pending EOF to send, send it */
  if (p->pending_eof)
    sk_write_eof(p->sub_socket);

  /* if the backend wanted the socket unfrozen, try to unfreeze.
   * our set_frozen handler will flush buffered receive data before
   * unfreezing the actual underlying socket.
   */
  if (!p->freeze)
    sk_set_frozen((Socket)p, 0);
}
Beispiel #2
0
static int sk_proxy_write_oob(Socket s, const char *data, int len) {
	Proxy_Socket ps = (Proxy_Socket) s;

	if (ps->state != PROXY_STATE_ACTIVE) {
		bufchain_clear(&ps->pending_output_data);
		bufchain_clear(&ps->pending_oob_output_data);
		bufchain_add(&ps->pending_oob_output_data, data, len);
		return len;
	}
	return sk_write_oob(ps->sub_socket, data, len);
}
Beispiel #3
0
static int sk_proxy_write_oob (Socket s, const void *data, int len)
{
    ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt);

    if (ps->state != PROXY_STATE_ACTIVE) {
	bufchain_clear(&ps->pending_output_data);
	bufchain_clear(&ps->pending_oob_output_data);
	bufchain_add(&ps->pending_oob_output_data, data, len);
	return len;
    }
    return sk_write_oob(ps->sub_socket, data, len);
}
Beispiel #4
0
static size_t sk_proxy_write_oob (Socket *s, const void *data, size_t len)
{
    ProxySocket *ps = container_of(s, ProxySocket, sock);

    if (ps->state != PROXY_STATE_ACTIVE) {
	bufchain_clear(&ps->pending_output_data);
	bufchain_clear(&ps->pending_oob_output_data);
	bufchain_add(&ps->pending_oob_output_data, data, len);
	return len;
    }
    return sk_write_oob(ps->sub_socket, data, len);
}