Exemplo n.º 1
0
void zmq::v2_encoder_t::message_ready ()
{
    //  Encode flags.
    unsigned char &protocol_flags = tmpbuf [0];
    protocol_flags = 0;
    if (in_progress->flags () & msg_t::more)
        protocol_flags |= v2_protocol_t::more_flag;
    if (in_progress->size () > 255)
        protocol_flags |= v2_protocol_t::large_flag;
    if (in_progress->flags () & msg_t::command)
        protocol_flags |= v2_protocol_t::command_flag;

    //  Encode the message length. For messages less then 256 bytes,
    //  the length is encoded as 8-bit unsigned integer. For larger
    //  messages, 64-bit unsigned integer in network byte order is used.
    const size_t size = in_progress->size ();
    if (unlikely (size > 255)) {
        put_uint64 (tmpbuf + 1, size);
        next_step (tmpbuf, 9, &v2_encoder_t::size_ready, false);
    }
    else {
        tmpbuf [1] = static_cast <uint8_t> (size);
        next_step (tmpbuf, 2, &v2_encoder_t::size_ready, false);
    }
}
Exemplo n.º 2
0
bool zmq::decoder_t::one_byte_size_ready ()
{
    //  First byte of size is read. If it is 0xff read 8-byte size.
    //  Otherwise allocate the buffer for message data and read the
    //  message data into it.
    if (*tmpbuf == 0xff)
        next_step (tmpbuf, 8, &decoder_t::eight_byte_size_ready);
    else {

        //  There has to be at least one byte (the flags) in the message).
        if (!*tmpbuf) {
            decoding_error ();
            return false;
        }

        //  in_progress is initialised at this point so in theory we should
        //  close it before calling zmq_msg_init_size, however, it's a 0-byte
        //  message and thus we can treat it as uninitialised...
        int rc = zmq_msg_init_size (&in_progress, *tmpbuf - 1);
        if (rc != 0 && errno == ENOMEM) {
            rc = zmq_msg_init (&in_progress);
            errno_assert (rc == 0);
            decoding_error ();
            return false;
        }
        errno_assert (rc == 0);

        next_step (tmpbuf, 1, &decoder_t::flags_ready);
    }
    return true;
}
Exemplo n.º 3
0
int zmq::v1_decoder_t::one_byte_size_ready (unsigned char const*)
{
    //  First byte of size is read. If it is 0xff read 8-byte size.
    //  Otherwise allocate the buffer for message data and read the
    //  message data into it.
    if (*tmpbuf == 0xff)
        next_step (tmpbuf, 8, &v1_decoder_t::eight_byte_size_ready);
    else {

        //  There has to be at least one byte (the flags) in the message).
        if (!*tmpbuf) {
            errno = EPROTO;
            return -1;
        }

        if (maxmsgsize >= 0 && (int64_t) (*tmpbuf - 1) > maxmsgsize) {
            errno = EMSGSIZE;
            return -1;
        }

        int rc = in_progress.close();
        assert(rc == 0);
        rc = in_progress.init_size (*tmpbuf - 1);
        if (rc != 0) {
            errno_assert (errno == ENOMEM);
            rc = in_progress.init ();
            errno_assert (rc == 0);
            errno = ENOMEM;
            return -1;
        }

        next_step (tmpbuf, 1, &v1_decoder_t::flags_ready);
    }
    return 0;
}
Exemplo n.º 4
0
bool zmq::bp_decoder_t::one_byte_size_ready ()
{
    //  First byte of size is read. If it is 0xff read 8-byte size.
    //  Otherwise allocate the buffer for message data and read the
    //  message data into it.
    if (*tmpbuf == 0xff)
        next_step (tmpbuf, 8, &bp_decoder_t::eight_byte_size_ready);
    else {
        message.rebuild (*tmpbuf);
        next_step (message.data (), *tmpbuf, &bp_decoder_t::message_ready);
    }
    return true;
}
Exemplo n.º 5
0
bool zmq::v1_decoder_t::flags_ready ()
{
    msg_flags = 0;
    if (tmpbuf [0] & v1_protocol_t::more_flag)
        msg_flags |= msg_t::more;

    //  The payload length is either one or eight bytes,
    //  depending on whether the 'large' bit is set.
    if (tmpbuf [0] & v1_protocol_t::large_flag)
        next_step (tmpbuf, 8, &v1_decoder_t::eight_byte_size_ready);
    else
        next_step (tmpbuf, 1, &v1_decoder_t::one_byte_size_ready);

    return true;
}
Exemplo n.º 6
0
bool zmq::raw_encoder_t::raw_message_ready ()
{
    //  Destroy content of the old message.
    int rc = in_progress.close ();
    errno_assert (rc == 0);

    //  Read new message. If there is none, return false.
    //  Note that new state is set only if write is successful. That way
    //  unsuccessful write will cause retry on the next state machine
    //  invocation.
    if (unlikely (!msg_source)) {
        rc = in_progress.init ();
        errno_assert (rc == 0);
        return false;
    }
    rc = msg_source->pull_msg (&in_progress);
    if (unlikely (rc != 0)) {
        errno_assert (errno == EAGAIN);
        rc = in_progress.init ();
        errno_assert (rc == 0);
        return false;
    }

    in_progress.reset_flags(0xff);
    next_step (NULL, 0, &raw_encoder_t::raw_message_size_ready, true);

    return true;
}
Exemplo n.º 7
0
bool zmq::v1_encoder_t::size_ready ()
{
    //  Write message body into the buffer.
    next_step (in_progress.data (), in_progress.size (),
        &v1_encoder_t::message_ready, !(in_progress.flags () & msg_t::more));
    return true;
}
Exemplo n.º 8
0
int zmq::v2_decoder_t::message_ready (unsigned char const*)
{
    //  Message is completely read. Signal this to the caller
    //  and prepare to decode next message.
    next_step (tmpbuf, 1, &v2_decoder_t::flags_ready);
    return 1;
}
Exemplo n.º 9
0
int zmq::v2_decoder_t::one_byte_size_ready ()
{
    //  Message size must not exceed the maximum allowed size.
    if (maxmsgsize >= 0)
        if (unlikely (tmpbuf [0] > static_cast <uint64_t> (maxmsgsize))) {
            errno = EMSGSIZE;
            return -1;
        }

    //  in_progress is initialised at this point so in theory we should
    //  close it before calling zmq_msg_init_size, however, it's a 0-byte
    //  message and thus we can treat it as uninitialised...
    int rc = in_progress.init_size (tmpbuf [0]);
    if (unlikely (rc)) {
        errno_assert (errno == ENOMEM);
        rc = in_progress.init ();
        errno_assert (rc == 0);
        errno = ENOMEM;
        return -1;
    }

    in_progress.set_flags (msg_flags);
    next_step (in_progress.data (), in_progress.size (),
        &v2_decoder_t::message_ready);

    return 0;
}
Exemplo n.º 10
0
int zmq::v1_decoder_t::message_ready ()
{
    //  Message is completely read. Push it further and start reading
    //  new message. (in_progress is a 0-byte message after this point.)
    next_step (tmpbuf, 1, &v1_decoder_t::one_byte_size_ready);
    return 1;
}
Exemplo n.º 11
0
bool zmq::zmq_encoder_t::size_ready ()
{
    //  Write message body into the buffer.
    if (!trim) {
        next_step (zmq_msg_data (&in_progress), zmq_msg_size (&in_progress),
            &zmq_encoder_t::message_ready, false);
    }
    else {
        size_t prefix_size = *(unsigned char*) zmq_msg_data (&in_progress);
        next_step (
            (unsigned char*) zmq_msg_data (&in_progress) + prefix_size + 1,
            zmq_msg_size (&in_progress) - prefix_size - 1,
            &zmq_encoder_t::message_ready, false);
    }
    return true;
}
Exemplo n.º 12
0
bool zmq::decoder_t::eight_byte_size_ready ()
{
    //  8-byte size is read. Allocate the buffer for message body and
    //  read the message data into it.
    size_t size = (size_t) get_uint64 (tmpbuf);

    //  There has to be at least one byte (the flags) in the message).
    if (!size) {
        decoding_error ();
        return false;
    }

    //  in_progress is initialised at this point so in theory we should
    //  close it before calling zmq_msg_init_size, however, it's a 0-byte
    //  message and thus we can treat it as uninitialised...
    int rc;
    if (maxmsgsize >= 0 && (int64_t) (size - 1) > maxmsgsize) {
        rc = -1;
        errno = ENOMEM;
    }
    else
        rc = in_progress.init_size (size - 1);
    if (rc != 0 && errno == ENOMEM) {
        rc = in_progress.init ();
        errno_assert (rc == 0);
        decoding_error ();
        return false;
    }
    errno_assert (rc == 0);

    next_step (tmpbuf, 1, &decoder_t::flags_ready);
    return true;
}
Exemplo n.º 13
0
void dummy3(void) {
  void* cfa = (void*) __builtin_dwarf_cfa();
  printf("cfa: %p\n", cfa);
  ASSERT(dummy0_cfa == cfa, "ERROR: cfa mismatch");

  next_step(5);
  exit(55);
}
Exemplo n.º 14
0
void dummy1(void) {
  void* cfa = (void*) __builtin_dwarf_cfa();
  printf("cfa: %p\n", cfa);
  ASSERT(dummy0_cfa == cfa, "ERROR: cfa mismatch");

  next_step(3);
  __builtin_eh_return (STACK_REMAINDER, dummy2);
}
Exemplo n.º 15
0
int zmq::v2_decoder_t::flags_ready (unsigned char const*)
{
    msg_flags = 0;
    if (tmpbuf [0] & v2_protocol_t::more_flag)
        msg_flags |= msg_t::more;
    if (tmpbuf [0] & v2_protocol_t::command_flag)
        msg_flags |= msg_t::command;

    //  The payload length is either one or eight bytes,
    //  depending on whether the 'large' bit is set.
    if (tmpbuf [0] & v2_protocol_t::large_flag)
        next_step (tmpbuf, 8, &v2_decoder_t::eight_byte_size_ready);
    else
        next_step (tmpbuf, 1, &v2_decoder_t::one_byte_size_ready);

    return 0;
}
Exemplo n.º 16
0
bool zmq::v1_encoder_t::message_ready ()
{
    //  Release the content of the old message.
    int rc = in_progress.close ();
    errno_assert (rc == 0);

    //  Read new message. If there is none, return false.
    //  Note that new state is set only if write is successful. That way
    //  unsuccessful write will cause retry on the next state machine
    //  invocation.
    if (unlikely (!msg_source)) {
        rc = in_progress.init ();
        errno_assert (rc == 0);
        return false;
    }

    rc = msg_source->pull_msg (&in_progress);
    if (unlikely (rc)) {
        errno_assert (errno == EAGAIN);
        rc = in_progress.init ();
        errno_assert (rc == 0);
        return false;
    }

    //  Encode flags.
    unsigned char &protocol_flags = tmpbuf [0];
    protocol_flags = 0;
    if (in_progress.flags () & msg_t::more)
        protocol_flags |= v1_protocol_t::more_flag;
    if (in_progress.size () > 255)
        protocol_flags |= v1_protocol_t::large_flag;

    //  Encode the message length. For messages less then 256 bytes,
    //  the length is encoded as 8-bit unsigned integer. For larger
    //  messages, 64-bit unsigned integer in network byte order is used.
    const size_t size = in_progress.size ();
    if (unlikely (size > 255)) {
        put_uint64 (tmpbuf + 1, size);
        next_step (tmpbuf, 9, &v1_encoder_t::size_ready, false);
    }
    else {
        tmpbuf [1] = static_cast <uint8_t> (size);
        next_step (tmpbuf, 2, &v1_encoder_t::size_ready, false);
    }
    return true;
}
Exemplo n.º 17
0
void zmq::bp_decoder_t::reset ()
{
    //  Free the message buffer.
    message.rebuild (0);

    //  Restart the FSM.
    next_step (tmpbuf, 1, &bp_decoder_t::one_byte_size_ready);
}
Exemplo n.º 18
0
bool zmq::bp_decoder_t::eight_byte_size_ready ()
{
    //  8-byte size is read. Allocate the buffer for message body and
    //  read the message data into it.
    message.rebuild ((size_t) get_uint64 (tmpbuf));
    next_step (message.data (), message.size (), &bp_decoder_t::message_ready);
    return true;
}
Exemplo n.º 19
0
int main(int argc, char *argv[])
{
    int p, x, y, val, cost, dir, ttl, wall_cost;
    unsigned long long score = 0, got;
    int i;

    scanf ("%d %d %d", &max_x, &max_y, &wall_cost);
    scanf ("%d", &p);
    
    max_x--;
    max_y--;

    /* Create walls */
    for (i = 0; i <= max_x; i++) {
        bumps[i][0] = bumps[i][max_y] = 2;
        values[i][0] = values[i][max_y] = 0;
        costs[i][0] = costs[i][max_y] = wall_cost;
    }

    for (i = 0; i <= max_y; i++) {
        bumps[0][i] = bumps[max_x][i] = 2;
        values[0][i] = values[max_x][i] = 0;
        costs[0][i] = costs[max_x][i] = wall_cost;
    }

    if (p) {
        while (p--) {
            scanf ("%d %d %d %d", &x, &y, &val, &cost);
            x--;
            y--;
            bumps[x][y] = 1;
            values[x][y] = val;
            costs[x][y] = cost;
        }
    }

    while (scanf ("%d %d %d %d", &x, &y, &dir, &ttl) == 4) {
        got = 0;
        x--;
        y--;

#ifdef DEBUG
        printf ("\nNew ball @(%d,%d), dir = %d, ttl = %d\n", x+1, y+1, dir, ttl);
#endif

        while (ttl > 0) {
            next_step (&x, &y, &dir, &got, &ttl);
            if (ttl <= 0)
                break;
        }

        score += got;
        printf ("%llu\n", got);
    }

    printf ("%llu\n", score);
    return 0;
}
Exemplo n.º 20
0
zmq::decoder_t::decoder_t (size_t bufsize_) :
    decoder_base_t <decoder_t> (bufsize_),
    destination (NULL)
{
    zmq_msg_init (&in_progress);

    //  At the beginning, read one byte and go to one_byte_size_ready state.
    next_step (tmpbuf, 1, &decoder_t::one_byte_size_ready);
}
void
control_connection_start_watches(ControlConnection *s)
{
  next_step = s->handle_input;
  while(next_step)
    {
      next_step(s);
    }
}
Exemplo n.º 22
0
bool zmq::decoder_t::flags_ready ()
{
    //  Store the flags from the wire into the message structure.
    in_progress.flags = tmpbuf [0] | ~ZMQ_MSG_MASK;

    next_step (zmq_msg_data (&in_progress), zmq_msg_size (&in_progress),
        &decoder_t::message_ready);

    return true;
}
Exemplo n.º 23
0
bool zmq::decoder_t::flags_ready ()
{
    //  Store the flags from the wire into the message structure.
    in_progress.set_flags (tmpbuf [0]);

    next_step (in_progress.data (), in_progress.size (),
        &decoder_t::message_ready);
    
    return true;
}
Exemplo n.º 24
0
bool zmq::bp_decoder_t::message_ready ()
{
    //  Message is completely read. Push it to the dispatcher and start reading
    //  new message.
    if (!demux->write (message))
        return false;

    next_step (tmpbuf, 1, &bp_decoder_t::one_byte_size_ready);
    return true;
}
Exemplo n.º 25
0
zmq::zmq_encoder_t::zmq_encoder_t (size_t bufsize_) :
    encoder_t <zmq_encoder_t> (bufsize_),
    source (NULL),
    trim (false)
{
    zmq_msg_init (&in_progress);

    //  Write 0 bytes to the batch and go to message_ready state.
    next_step (NULL, 0, &zmq_encoder_t::message_ready, true);
}
Exemplo n.º 26
0
zmq::v1_encoder_t::v1_encoder_t (size_t bufsize_, i_msg_source *msg_source_) :
    encoder_base_t <v1_encoder_t> (bufsize_),
    msg_source (msg_source_)
{
    int rc = in_progress.init ();
    errno_assert (rc == 0);

    //  Write 0 bytes to the batch and go to message_ready state.
    next_step (NULL, 0, &v1_encoder_t::message_ready, true);
}
Exemplo n.º 27
0
zmq::v1_decoder_t::v1_decoder_t (size_t bufsize_, int64_t maxmsgsize_) :
    decoder_base_t <v1_decoder_t> (bufsize_),
    maxmsgsize (maxmsgsize_)
{
    int rc = in_progress.init ();
    errno_assert (rc == 0);

    //  At the beginning, read one byte and go to one_byte_size_ready state.
    next_step (tmpbuf, 1, &v1_decoder_t::one_byte_size_ready);
}
Exemplo n.º 28
0
bool zmq::decoder_t::message_ready ()
{
    //  Message is completely read. Push it further and start reading
    //  new message. (in_progress is a 0-byte message after this point.)
    if (!destination || !destination->write (&in_progress))
        return false;

    next_step (tmpbuf, 1, &decoder_t::one_byte_size_ready);
    return true;
}
Exemplo n.º 29
0
static void Init(rtems_task_argument arg)
{
#ifdef RTEMS_POSIX_API
  pthread_cleanup_push(NULL, NULL);
  pthread_cleanup_pop(0);
#endif /* RTEMS_POSIX_API */
  next_step(INIT_TASK);
  rtems_test_endk();
  exit(0);
}
Exemplo n.º 30
0
int zmq::v1_decoder_t::flags_ready ()
{
    //  Store the flags from the wire into the message structure.
    in_progress.set_flags (tmpbuf [0] & msg_t::more);

    next_step (in_progress.data (), in_progress.size (),
        &v1_decoder_t::message_ready);

    return 0;
}