]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Change in in fwp_msgb: addr is pointer to include unix/inet address and head changed...
authorMartin Molnar <molnar@sum.(none)>
Sun, 20 Jan 2008 15:20:33 +0000 (16:20 +0100)
committerMartin Molnar <molnar@sum.(none)>
Sun, 20 Jan 2008 15:20:33 +0000 (16:20 +0100)
fwp/fwp_manager/fwpmgr.c
fwp/libfwp/include/fwp_msgb.h
fwp/libfwp/src/fwp_ac.c
fwp/libfwp/src/fwp_msgb.c
fwp/libfwp/src/fwp_proto.c
fwp/libfwp/src/fwp_vres.c

index a8092b4300d67dacdca0da30d96c9a8b4882bebd..b4cdf0a1db147b1b0b362eb5875cf8a32da74f7c 100644 (file)
@@ -66,7 +66,7 @@ void fwp_mngr_admctrl(void *arg)
                if (ctentry[id].contract.status == FWP_NEGOTIATED )
                        fwp_ctable_put(&ctable_accepted, &ctentry[id]);
 
-               msgb->data = msgb->head;
+               msgb->data = msgb->start;
                fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));
                fwp_msg_contract_put(msgb, &ctentry[id].contract);      
                        
@@ -122,7 +122,7 @@ void fwp_agent_negotiate_request(unsigned int hid, struct fwp_msgb *msgb)
        ctentry.hid = hid;
        hid = fwp_ctable_put(&ctable_negotiate, &ctentry);
 
-       msgb->data =  msgb->head;
+       msgb->data =  msgb->start;
        fwp_msg_header_put(msgb, FWP_NEGT_REQ, hid); 
        msgb->addrlen = sizeof(fwp_mngr_addr);
        memcpy(&msgb->addr, (struct sockaddr*)&fwp_mngr_addr, msgb->addrlen);
@@ -279,7 +279,7 @@ void* fwp_mngr(fwp_mngr_mode_t mode)
                msgb = fwp_msgb_alloc(len);
                memcpy(&msgb->addr, (struct sockaddr*)&peer_addr, peer_addrlen);
                msgb->addrlen = peer_addrlen;
-               memcpy(msgb->head, buffer, len);
+               memcpy(msgb->start, buffer, len);
                msgb->len = len;
 
                if (mode == FWP_AGENT)
index c876481d63a6b97555aeb9e3dc7790e474763c11..545b8c7098a1577bf3b60181f0147b28f595af37 100644 (file)
@@ -9,13 +9,13 @@
 #include <unistd.h>*/
 
 struct fwp_msgb {
-       struct sockaddr addr;
        socklen_t addrlen;
-       unsigned char* head;
-       unsigned char* data;
-       unsigned char* tail;
-       size_t len;
        size_t buf_size;
+       unsigned char *addr;    /**< destination address*/
+       unsigned char *start;   /**< msg data start*/ 
+       unsigned char *data;    /**< msg data */
+       unsigned char *tail;    /**< msg data end*/
+       size_t len;             /**< msg data length*/
        /*int flags;  MSG_DONTWAIT for async*/
 };
 
index 96ae15147d184c611788ed1043095b4be99be0af..b2f574b0d64aef721d32689ca9a767efe5e76d8a 100644 (file)
@@ -92,8 +92,9 @@ int fwp_ac_send(unsigned int id, struct fwp_msgb* msgb)
 {
        /*if (!msgb)
                return -EINVAL;*/
-       while (sendto(fwp_ac_table[id].sockfd, msgb->head, msgb->len,
-                     /*msgb_>flags*/0, &msgb->addr, msgb->addrlen) < 0) {
+       while (sendto(fwp_ac_table[id].sockfd, msgb->start, msgb->len,
+                     /*msgb_>flags*/0, (struct sockaddr*)msgb->addr, 
+                     msgb->addrlen) < 0) {
 
                if (errno == EINTR) continue;
                perror("fwp_ac_send - Error while sending data");
index ad1e4531d2f60223b70fd1eb0b2351c833c09f13..10ecfd5f378c593d7cc73b93f2e0aca49dac62d0 100644 (file)
@@ -11,15 +11,20 @@ struct fwp_msgb* fwp_msgb_alloc(size_t buf_size)
        /*fwp_msgb_pool_dequeue; other choice*/
 
        msgb = (struct fwp_msgb*) malloc(sizeof(struct fwp_msgb) + buf_size);
-       msgb->head =  (unsigned char*) msgb + sizeof(struct fwp_msgb);
-       msgb->data = msgb->tail = msgb->head;
+       if (!msgb)
+               return NULL;
+       
        msgb->buf_size = buf_size;
+       msgb->start = (unsigned char*) msgb + sizeof(struct fwp_msgb);
+       msgb->data = msgb->tail = msgb->start;
        msgb->len = 0;
+       msgb->addr = NULL;
+       msgb->addrlen = 0;
 
        return msgb;
 }
 
-void fwp_msgb_free(struct fwp_msgbmsgb)
+void fwp_msgb_free(struct fwp_msgb *msgb)
 {
        free((void*) msgb);
        msgb = NULL;
index 29a1a14fae35aaa73149c824ff37af764cb9b554..8974dd5631b384e6b86adf1f2332c3887cea5d9a 100644 (file)
@@ -8,8 +8,8 @@
 
 struct sockaddr_in fwp_mngr_addr;
 struct sockaddr_un fwp_agent_addr;
-int sockfd_agent;
-int sockfd_mngr;
+int    sockfd_agent;
+int    sockfd_mngr;
 
 
 int fwp_init()
@@ -70,7 +70,6 @@ ssize_t fwp_recv(int sockfd, void *buffer, size_t buffer_size, int flags,
        return len;
 }
 
-
 int fwp_send(unsigned int vres_id, void *buffer, size_t size, int flags, 
             struct sockaddr *to, socklen_t tolen)
 {
@@ -83,16 +82,18 @@ int fwp_send(unsigned int vres_id, void *buffer, size_t size, int flags,
        /*if (flags && MSG_DONTWAIT) 
                msgb = fwp_msgb_alloc(buffer_size);
        else {*/
-               if (!(msgb = fwp_msgb_alloc(0)))
+               if (!(msgb = fwp_msgb_alloc(tolen)))
                        return -ENOMEM;
 
-               msgb->head = msgb->data = buffer;
-               msgb->tail = msgb->head + size;
-               msgb->buf_size = msgb->len = size;
+               msgb->buf_size = msgb->addrlen = tolen; 
+               msgb->addr = msgb->start;
+               msgb->start = msgb->data = buffer;
+               msgb->tail = msgb->start + size;
+               msgb->len = size;
 
        /*}*/
 
-       memcpy((void*)&msgb->addr, (void*)to, tolen);
+       memcpy((void*)msgb->addr, (void*)to, tolen);
        msgb->addrlen = tolen;
        
        return fwp_vres_send(vres_id, msgb);
@@ -106,25 +107,21 @@ int fwp_contract_negotiate (struct fwp_contract *contract)
        msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) + 
                              sizeof(struct fwp_msg_contract));
        
-       if (msgb == NULL) return -1;
+       if (!msgb) 
+               return -ENOMEM;
        
        fwp_msg_header_put(msgb, FWP_NEGT_REQ, 0);
        fwp_msg_contract_put(msgb, contract);
        
-       /*sendto FWP agent through unix socket 
+       /* sendto FWP agent through unix socket 
         * and wait for reply
         */
        
-       msgb->addrlen = sizeof(fwp_agent_addr);
-       memcpy((void*)&msgb->addr, (void*)&fwp_agent_addr, msgb->addrlen);
-       
-       /*fwp_vres_send(vres_id, msgb);*/
-
        connect(sockfd_agent, (struct sockaddr *)&fwp_agent_addr, 
                sizeof(fwp_agent_addr));
        
-       send(sockfd_agent, msgb->head, msgb->len, 0); 
-       recv(sockfd_agent, msgb->head, msgb->buf_size, 0); 
+       send(sockfd_agent, msgb->start, msgb->len, 0); 
+       recv(sockfd_agent, msgb->start, msgb->buf_size, 0); 
        
        fwp_msg_header_pull(msgb, &code, &hid);
        fwp_msg_contract_pull(msgb, contract);
index 3ca2a85d4042e4dc148c3b8c0649f8d020be0997..188e29dd6ebe0f4bd2fbbb49448c82d05c143a29 100644 (file)
@@ -152,7 +152,7 @@ static void* fwp_vres_tx_thread(void *_vres)
                        /* TODO: rc handling */
                        printf("Posilam\n");
                        rc = fwp_ac_send(ac_id, msgb);
-                       fwp_msgb_free(msgb);
+                       //fwp_msgb_free(msgb);
                }
 
                fwp_timespec_add(&end_period, &start_period, &period);