Exemplo n.º 1
0
static void
issue_calls (Sess *sess, Sess_Private_Data *priv)
{
  int i, to_create, retval;
  Call *call;

  /* Mimic browser behavior of fetching html object, then a couple of
     embedded objects: */

  to_create = 1;
  if (priv->num_calls_in_this_burst > 0)
    to_create = param.burst_len - priv->num_calls_in_this_burst;

  priv->num_calls_in_this_burst += to_create;

  for (i = 0; i < to_create; ++i)
    {
      call = call_new ();
      if (!call)
	{
	  sess_failure (sess);
	  return;
	}

      retval = session_issue_call (sess, call);
      call_dec_ref (call);

      if (retval < 0)
	return;
    }
}
Exemplo n.º 2
0
static void
sess_destroyed (Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg)
{
  Sess_Private_Data *priv;
  struct Conn_Info *ci;
  Sess *sess;
  int i, j, rd;

  assert (et == EV_SESS_DESTROYED && object_is_sess (obj));
  sess = (Sess *) obj;
  priv = SESS_PRIVATE_DATA (sess);

  for (i = 0; i < param.max_conns; ++i)
    {
      ci = priv->conn_info + i;

      if (ci->conn)
	core_close (ci->conn);

      rd = ci->rd;
      for (j = 0; j < ci->num_pending; ++j)
	{
	  call_dec_ref (ci->call[rd]);
	  rd = (rd + 1) % MAX_PIPED;
	}
    }
}
Exemplo n.º 3
0
static void
issue_calls (Sess *sess, Sess_Private_Data *priv)
{
  int i, to_create, retval, n;
  const char *method_str;
  Call *call;
  REQ *req;

  /* Mimic browser behavior of fetching html object, then a couple of
     embedded objects: */

  to_create = 1;
  if (priv->num_calls_in_this_burst > 0)
    to_create = priv->current_burst->num_reqs - priv->num_calls_in_this_burst;

  n = session_max_qlen (sess) - session_current_qlen (sess);
  if (n < to_create)
    to_create = n;

  priv->num_calls_in_this_burst += to_create;

  for (i = 0; i < to_create; ++i)
    {
      call = call_new ();
      if (!call)
	{
	  sess_failure (sess);
	  return;
	}

      /* fill in the new call: */
      req = priv->current_req;
      if (req == NULL)
	panic ("%s: internal error, requests ran past end of burst\n",
	       prog_name);

      method_str = call_method_name[req->method];
      call_set_method (call, method_str, strlen (method_str));
      call_set_uri (call, req->uri, req->uri_len);
      if (req->contents_len > 0)
	{
	  /* add "Content-length:" header and contents, if necessary: */
	  call_append_request_header (call, req->extra_hdrs,
				      req->extra_hdrs_len);
	  call_set_contents (call, req->contents, req->contents_len);
	}
      priv->current_req = req->next;

      if (DBG > 0)
	fprintf (stderr, "%s: accessing URI `%s'\n", prog_name, req->uri);

      retval = session_issue_call (sess, call);
      call_dec_ref (call);

      if (retval < 0)
	return;
    }
}
Exemplo n.º 4
0
static void
issue_calls (Sess *sess, Sess_Private_Data *priv)
{
  int i, to_create, retval, embedded = 0;
  Call_Private_Data *cpriv;
  struct uri_list *el;
  Call *call;

  /* Mimic browser behavior of fetching html object, then a couple of
     embedded objects: */

  to_create = 1;
  if (priv->num_created > 0)
    {
      to_create = session_max_qlen (sess) - session_current_qlen (sess);
      embedded = 1;
    }

  for (i = 0; i < to_create && (!embedded || priv->uri_list); ++i)
    {
      ++priv->num_created;

      call = call_new ();
      if (!call)
	{
	  sess_failure (sess);
	  return;
	}
      if (embedded)
	{
	  el = priv->uri_list;
	  priv->uri_list = el->next;

	  cpriv = CALL_PRIVATE_DATA (call);
	  cpriv->to_free = el;
	  call_set_uri (call, el->uri, el->uri_len);
	}

      if (verbose > 1)
	printf ("%s: fetching `%s'\n",
		prog_name, (char *)call->req.iov[IE_URI].iov_base);

      retval = session_issue_call (sess, call);
      call_dec_ref (call);
      if (retval < 0)
	return;
    }
}
Exemplo n.º 5
0
static void
call_done (Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg)
{
  Conn_Private_Data *cpriv;
  struct Conn_Info *ci;
  Sess *sess;
  Conn *conn;
  Call *call;

  assert (et == EV_CALL_RECV_STOP && object_is_call (obj));
  call = (Call *) obj;
  conn = call->conn;
  cpriv = CONN_PRIVATE_DATA (conn);
  sess = cpriv->sess;
  ci = cpriv->ci;

  ci->is_successful = 1;	/* conn has received at least one reply */

  /* remove the call from the conn_info structure */
  assert (ci->call[ci->rd] == call && ci->num_pending > 0 && ci->num_sent > 0);
  ci->call[ci->rd] = 0;
  ci->rd = (ci->rd + 1) % MAX_PIPED;
  --ci->num_pending;
  --ci->num_sent;

  /* if the reply status matches the failure status, the session has
     failed */
  if (param.failure_status && call->reply.status == param.failure_status)
    {
      if (param.retry_on_failure)
	session_issue_call (sess, call);
      else
	sess_failure (sess);
    }

  call_dec_ref (call);

  if (param.http_version < 0x10001)
    {
      /* Rather than waiting for the connection to close on us, we
	 close it pro-actively (this is what a pre-1.1 browser would
	 do.  */
      core_close (ci->conn);
      ci->conn = 0;
    }
}
Exemplo n.º 6
0
unsigned char* zmq::shared_message_memory_allocator::allocate()
{
    if (buf)
    {
        // release reference count to couple lifetime to messages
        call_dec_ref(NULL, buf);
        // release pointer because we are going to create a new buffer
        release();
    }

    // @todo aligmnet padding may be needed
    if (!buf)
    {
        buf = (unsigned char *) malloc(bufsize + sizeof(zmq::atomic_counter_t));
        alloc_assert (buf);
        new(buf) atomic_counter_t(1);
    }

    return buf + sizeof( zmq::atomic_counter_t);
}
Exemplo n.º 7
0
static void
issue_calls (Sess *sess, Sess_Private_Data *priv)
{
  int  retval;
  const char *method_str;
  Call *call;
  REQ *req;
  
  call = call_new ();
  if (!call)
  {
	sess_failure (sess);
	return;
  }

  req = priv->current_req;
  if (req == NULL)
	panic ("%s: internal error, requests ran past end of session\n",
	       prog_name);
  method_str = call_method_name[req->method];
  call_set_method (call, method_str, strlen (method_str));
  call_set_uri (call, req->uri, req->uri_len);
  if (req->contents_len > 0)
  {
	 /* add "Content-length:" header and contents, if necessary: */
	  call_append_request_header (call, req->extra_hdrs,
				      req->extra_hdrs_len);
	  call_set_contents (call, req->contents, req->contents_len);
  }

  if (DBG > 0)
	fprintf (stderr, "%s: accessing URI `%s'\n", prog_name, req->uri);
        retval = session_issue_call (sess, call);
	
	call_dec_ref (call);

      if (retval < 0)
	return;

}
Exemplo n.º 8
0
	static void
issue_calls (Sess *sess, Sess_Private_Data *priv)
{
	int i, to_create, retval, n;
	const char *method_str;
	Call *call;
	REQ *req;

	/* Mimic browser behavior of fetching html object, then a couple of
	   embedded objects: */

	to_create = 1;

	if (priv->num_calls_in_this_burst > 0)
	{
		to_create = priv->current_burst->num_reqs - priv->num_calls_in_this_burst;
	}

	n = session_max_qlen (sess) - session_current_qlen (sess);
	if (n < to_create)
	{
		to_create = n;
	}

	priv->num_calls_in_this_burst += to_create; 

	for (i = 0; i < to_create; ++i)
	{
		call = call_new ();
		if (!call)
		{
			sess_failure (sess);
			return;
		}

		/* fill in the new call: */
		req = priv->current_req;
		if (req == NULL)
		{
			panic ("%s: internal error, requests ran past end of burst\n",prog_name);
		}

		call_set_version (call, priv->http_version);
		method_str = call_method_name[req->method];
		call_set_method (call, method_str, strlen (method_str));
		call_set_uri (call, req->uri, req->uri_len);

#ifdef UW_DYNOUT
		call->timelimit = req->timelimit;
#endif /* UW_DYNOUT */

		/* used for call stats */
		call->file_size = req->file_size;

		if (req->cookie_len > 0)
		{
			/* add "Cookie:" header if necessary: */
			call_append_request_header (call, req->cookie, req->cookie_len);
		}
#ifdef WSESSLOG_HEADERS
		if (req->contents_len > 0 || req->extra_hdrs_len > 0)
		{
			/* add "Content-length:" header and contents, if necessary: */
			call_append_request_header (call, req->extra_hdrs,
					req->extra_hdrs_len);
			if (req->contents_len > 0)
			{
				call_set_contents(call, req->contents, req->contents_len);
			}
		}
#else
		if (req->extra_hdrs_len > 0)
		{
			/* add "Content-length:" header and contents, if necessary: */
			call_append_request_header (call, req->extra_hdrs,
					req->extra_hdrs_len);
			call_set_contents (call, req->contents, req->contents_len);
		}
#endif /* WSESSLOG_HEADERS */

#ifdef UW_CALL_STATS
		if (param.client.id >= 0)
		{
			sprintf (call->id_hdr, "Client-Id: %d %d\r\n", param.client.id, (int) call->id);

			call_append_request_header (call, call->id_hdr, strlen(call->id_hdr));
		}
#endif /* UW_CALL_STATS */

		priv->current_req = req->next;

		if (DBG > 0)
		{
			fprintf (stderr, "%s: accessing URI `%s'\n", prog_name, req->uri);
		}

		retval = session_issue_call (sess, call);
		call_dec_ref (call);

		if (retval < 0)
		{
			return;
		}
	}
}