Example #1
0
/*! Reads header data from the actual header of the message
 *  Remainig fragment buf and length is in frag->frag and frag->frag_len
 *
 * @return 0 on success */
long
gcs_act_proto_read (gcs_act_frag_t* frag, const void* buf, size_t buf_len)
{
    frag->proto_ver = ((uint8_t*)buf)[PROTO_PV_OFFSET];

    if (gu_unlikely(buf_len < PROTO_DATA_OFFSET)) {
        gu_error ("Action message too short: %zu, expected at least %d",
                  buf_len, PROTO_DATA_OFFSET);
        return -EBADMSG;
    }

    if (gu_unlikely(frag->proto_ver > PROTO_VERSION)) {
        gu_error ("Bad protocol version %d, expected %d",
                  frag->proto_ver, PROTO_VERSION);
        return -EPROTO; // this fragment should be dropped
    }

    ((uint8_t*)buf)[PROTO_PV_OFFSET] = 0x0;
    frag->act_id   = gu_be64(*(uint64_t*)buf);
    frag->act_size = gtohl  (((uint32_t*)buf)[2]);
    frag->frag_no  = gtohl  (((uint32_t*)buf)[3]);
    frag->act_type = ((uint8_t*)buf)[PROTO_AT_OFFSET];
    frag->frag     = ((uint8_t*)buf) + PROTO_DATA_OFFSET;
    frag->frag_len = buf_len - PROTO_DATA_OFFSET;

    /* return 0 or -EMSGSIZE */
    return ((frag->act_size > GCS_MAX_ACT_SIZE) * -EMSGSIZE);
}
Example #2
0
 ssize_t len (ssize_t offset) const
 {
     return gtohl(*(reinterpret_cast<uint32_t*>(req_ + offset)));
 }