]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Length of all messages is set to be multiple of 8
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 28 May 2009 02:13:15 +0000 (04:13 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 28 May 2009 02:13:15 +0000 (04:13 +0200)
This is to achieve proper alignment of headers on stream oriented connections.

src/iop.c

index 95c0443f54fd485070a092b1e39d3ec14910f056..c0434639f79881f33cd7aa4b35a607ad1434da5e 100644 (file)
--- a/src/iop.c
+++ b/src/iop.c
@@ -127,6 +127,9 @@ forb_iop_prepare_hello(FORB_CDR_Codec *codec,
                if (!serialize_addr(codec, src_addr)) return CORBA_FALSE;
        }
        if (!CORBA_string_serialize(codec, &orb_id)) return CORBA_FALSE;
+       /* All headers must be 8 byte aligned so align the length of
+        * this message */
+       if (!FORB_CDR_put_align(codec, 8)) return CORBA_FALSE; 
        if (!forb_iop_prepend_message_header(codec, forb_iop_HELLO)) return CORBA_FALSE;
        return CORBA_TRUE;
 }
@@ -224,6 +227,12 @@ forb_iop_send_reply(forb_t *forb,
                                             forb_iop_REPLY_HEADER_SIZE);
                forb_exception_serialize(codec, env);
        }
+       /* All headers must be 8 byte aligned so align the length of
+        * this message */
+       if (!FORB_CDR_put_align(codec, 8)) {
+               ul_logerr("Not enough space for tail align\n");
+               return;         /* FIXME: handle error (goto above)*/
+       }
        /* forb_iop_REPLY_HEADER_SIZE equals to 8 even if the real
         * header is shorter. We want reply data to be 8 byte
         * aligned */
@@ -519,6 +528,9 @@ process_message(forb_port_t *port, const forb_iop_message_header *mh,
                forb_peer_put(port->new_peer);
                port->new_peer = NULL;
        }
+
+       FORB_CDR_get_align(codec, 8);
+
        if (FORB_CDR_data_size(codec) != data_size - mh->message_size) {
                size_t processed = data_size - FORB_CDR_data_size(codec);
                ul_logmsg("Message of type %d handled incorrectly (size=%d, processed=%d); fixing\n",
@@ -687,6 +699,14 @@ forb_request_send(forb_request_t *req, CORBA_Environment *env)
 
        req->env = env;     /* Remember, where to return exceptions */
 
+       /* All headers must be 8 byte aligned so align the length of
+        * this message */
+       if (!FORB_CDR_put_align(&req->cdr_request, 8)) {
+               env->major = FORB_EX_INTERNAL;
+               ul_logerr("Not enough space for tail align\n");
+               return;
+       }
+
        ret = forb_iop_prepend_message_header(&req->cdr_request, forb_iop_REQUEST);
        if (!ret) {
                /* This should never happen */