]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/frsh_fwp/fwp_fna.c
Implemented synchronous and asynchronous sending
[frescor/fwp.git] / fwp / lib / frsh_fwp / fwp_fna.c
index ca7a4ab894f4556b712db0942403ad37d9036662..a51e55847d8ace225e8e6e047413aaedc54d7c3e 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)
 {
@@ -80,24 +82,27 @@ int fwp_fna_send_endpoint_created(fna_endpoint_data_t  *endpoint)
 {
        unsigned int node, port;
        fwp_endpoint_attr_t *attr;
-       fwp_endpoint_t *fwp_epoint;
+       struct fwp_endpoint *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)
 {
        unsigned int node,port;
        fwp_endpoint_attr_t *attr;
-       fwp_endpoint_t *fwp_epoint;
+       struct fwp_endpoint *fwp_epoint;
        int rv;
 
        node = (unsigned int) endpoint->destination;
@@ -118,7 +123,7 @@ int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
 int fwp_fna_send_endpoint_bind(fna_endpoint_data_t *endpoint, fna_vres_id_t vres)
 {
        return fwp_send_endpoint_bind(endpoint->protocol_info.body, 
-                                       (fwp_vres_d_t) vres->priv);
+                                       (struct fwp_vres *) vres->priv);
 }
 
 int fwp_fna_send_endpoint_unbind(fna_endpoint_data_t *endpoint)
@@ -132,33 +137,22 @@ int fwp_fna_endpoint_destroy(fna_endpoint_data_t  *endpoint)
 }
 
 /** FNA send routine */
-int fwp_fna_send(const fna_endpoint_data_t *endpoint, const void *msg, 
-                       const size_t size)
-{
-       fwp_endpoint_t *fwp_epoint;
-       int flags = 0;
-
-       fwp_epoint = endpoint->protocol_info.body;
-       return fwp_send(fwp_epoint, msg, size, flags);
-}
-
 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg, 
                        const size_t size)
 {
-       fwp_endpoint_t *fwp_epoint;
-       int flags = 0;
+       struct fwp_endpoint *fwp_epoint;
 
        fwp_epoint = endpoint->protocol_info.body;
-       return fwp_send(fwp_epoint, msg, size, flags);
+       return fwp_send_sync(fwp_epoint, msg, size);
 }
 
 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
                   const size_t size)
 {
-       fwp_endpoint_t *fwp_epoint;
+       struct fwp_endpoint *fwp_epoint;
 
-       fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
-       return fwp_send(fwp_epoint, msg, size, MSG_DONTWAIT);
+       fwp_epoint = (struct fwp_endpoint*) endpoint->protocol_info.body;       
+       return fwp_send_async(fwp_epoint, msg, size);
 }
 
 /** FNA receive routines */
@@ -167,11 +161,11 @@ 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;
-       fwp_endpoint_t *fwp_epoint;
+       ssize_t len;
+       struct fwp_endpoint *fwp_epoint;
        int flags = 0;
        
-       fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
+       fwp_epoint = (struct fwp_endpoint*) endpoint->protocol_info.body;
        len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
        if (len < 0) 
                return len;
@@ -187,17 +181,19 @@ 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;
-       fwp_endpoint_t *fwp_epoint;
+       ssize_t len;
+       struct fwp_endpoint *fwp_epoint;
        int flags = 0;
        
-       fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
+       fwp_epoint = (struct fwp_endpoint*) endpoint->protocol_info.body;
        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,17 +203,19 @@ 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;
-       fwp_endpoint_t *fwp_epoint;
+       ssize_t len;
+       struct fwp_endpoint *fwp_epoint;
        int flags = 0;
        
-       fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
+       fwp_epoint = (struct fwp_endpoint*) endpoint->protocol_info.body;
        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;
 }
@@ -243,7 +241,7 @@ fna_operations_t fwp_fna_operations = {
     .fna_resource_get_capacity = NULL,
     .fna_resource_get_total_weight = NULL,
     .fna_vres_decrease_capacity = NULL,
-    .fna_send_sync = NULL,
+    .fna_send_sync = fwp_fna_send_sync,
     .fna_send_async = fwp_fna_send_async,
     .fna_receive_sync = fwp_fna_receive_sync,
     .fna_receive_async = fwp_fna_receive_async,