]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/frsh_fwp/fwp_fna.c
Use endpoint attributes only if it has correct size
[frescor/fwp.git] / fwp / lib / frsh_fwp / fwp_fna.c
index 6538ed3780e8bc2efc3f80b7381232a2487da3c2..1c9a7e8e868340b76b4ae029cc15d25354fb16ee 100644 (file)
@@ -50,6 +50,8 @@
 #include "fwp_vres.h"
 #include "fwp.h"
 #include "fwp_res.h"
+#include "fwp_utils.h"
+#include "fwp_debug.h"
 
 int fwp_fna_init(const frsh_resource_id_t resource_id)
 {
@@ -58,8 +60,7 @@ int fwp_fna_init(const frsh_resource_id_t resource_id)
        if ((rv = fwp_init()))
                return rv;
 
-       return fra_fwp_init(frsh_forb_global.orb, frsh_forb_global.fcb,
-                               &frsh_forb_global.alloc_executor);
+       return fra_fwp_init();
 }
 
 int fwp_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
@@ -83,15 +84,18 @@ int fwp_fna_send_endpoint_created(fna_endpoint_data_t  *endpoint)
        fwp_endpoint_attr_t *attr;
        fwp_endpoint_t *fwp_epoint;
        int rv;
-
+       frsh_send_endpoint_protocol_info_t *spi;
+       
        node = (unsigned int) endpoint->destination;
        port = (unsigned int) endpoint->stream_id;
-       attr = (fwp_endpoint_attr_t*) endpoint->endpoint_protocol_info.send.body; 
+       attr = NULL;
+       
+       spi = &endpoint->endpoint_protocol_info.send;
+       if (spi->size == sizeof(fwp_endpoint_attr_t))
+               attr = (fwp_endpoint_attr_t*)spi->body; 
        rv = fwp_send_endpoint_create(node, port, attr, &fwp_epoint);
-       if (rv)
-               return rv;
        endpoint->protocol_info.body = fwp_epoint;
-       return 0;
+       return rv;
 }
 
 int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
@@ -111,6 +115,7 @@ int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
        endpoint->protocol_info.body = fwp_epoint;
        fwp_endpoint_get_params(fwp_epoint, &node, &port, attr);
        endpoint->stream_id = port;
+       FWP_DEBUG("PORT= %d\n", port);
 
        return 0;
 }
@@ -167,7 +172,7 @@ int fwp_fna_receive(const fna_endpoint_data_t *endpoint,
                        size_t *received_bytes, frsh_network_address_t *from)
 {
        unsigned int from_addr;
-       size_t len;
+       ssize_t len;
        fwp_endpoint_t *fwp_epoint;
        int flags = 0;
        
@@ -187,7 +192,7 @@ int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer,
                         frsh_network_address_t *from)
 {
        unsigned int from_addr;
-       size_t len;
+       ssize_t len;
        fwp_endpoint_t *fwp_epoint;
        int flags = 0;
        
@@ -195,9 +200,11 @@ int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer,
        len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
        if (len < 0) 
                return len;
-       
-       *received_bytes = len;
-       *from = from_addr;
+
+       if (received_bytes)
+               *received_bytes = len;
+       if (from)
+               *from = from_addr;
        
        return 0;
 }
@@ -207,7 +214,7 @@ int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer,
                         frsh_network_address_t *from)
 {
        unsigned int from_addr;
-       size_t len;
+       ssize_t len;
        fwp_endpoint_t *fwp_epoint;
        int flags = 0;
        
@@ -215,9 +222,11 @@ int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer,
        len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
        if (len < 0) 
                return len;
-       
-       *received_bytes = len;
-       *from = from_addr;
+
+       if (received_bytes)
+               *received_bytes = len;
+       if (from)
+               *from = from_addr;
        
        return 0;
 }