示例#1
0
void
reliable_mark_active_outgoing (struct reliable *rel, struct buffer *buf, int opcode)
{
  int i;
  for (i = 0; i < rel->size; ++i)
    {
      struct reliable_entry *e = &rel->array[i];
      if (buf == &e->buf)
	{
	  /* Write mode, increment packet_id (i.e. sequence number)
	     linearly and prepend id to packet */
	  packet_id_type net_pid;
	  e->packet_id = rel->packet_id++;
	  net_pid = htonpid (e->packet_id);
	  ASSERT (buf_write_prepend (buf, &net_pid, sizeof (net_pid)));
	  e->active = true;
	  e->opcode = opcode;
	  e->next_try = 0;
	  e->timeout = rel->initial_timeout;
	  dmsg (D_REL_DEBUG, "ACK mark active outgoing ID " packet_id_format, (packet_id_print_type)e->packet_id);
	  return;
	}
    }
  ASSERT (0);			/* buf not found in rel */
}
示例#2
0
/* removing all acknowledged entries from ack */
bool
reliable_ack_write(struct reliable_ack *ack,
                   struct buffer *buf,
                   const struct session_id *sid, int max, bool prepend)
{
    int i, j;
    uint8_t n;
    struct buffer sub;

    n = ack->len;
    if (n > max)
    {
        n = max;
    }
    sub = buf_sub(buf, ACK_SIZE(n), prepend);
    if (!BDEF(&sub))
    {
        goto error;
    }
    ASSERT(buf_write(&sub, &n, sizeof(n)));
    for (i = 0; i < n; ++i)
    {
        packet_id_type pid = ack->packet_id[i];
        packet_id_type net_pid = htonpid(pid);
        ASSERT(buf_write(&sub, &net_pid, sizeof(net_pid)));
        dmsg(D_REL_DEBUG, "ACK write ID " packet_id_format " (ack->len=%d, n=%d)", (packet_id_print_type)pid, ack->len, n);
    }
    if (n)
    {
        ASSERT(session_id_defined(sid));
        ASSERT(session_id_write(sid, &sub));
        for (i = 0, j = n; j < ack->len; )
            ack->packet_id[i++] = ack->packet_id[j++];
        ack->len = i;
    }

    return true;

error:
    return false;
}