]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Fixes in fwp_endpoint, split fwp_endpoint_cretae to fwp_send_endpoint and fwp_recv_en...
authorMartin Molnar <molnam1@fel.cvut.cz>
Tue, 29 Jan 2008 23:26:42 +0000 (00:26 +0100)
committerMartin Molnar <molnam1@fel.cvut.cz>
Tue, 29 Jan 2008 23:26:42 +0000 (00:26 +0100)
fwp/libfwp/include/fwp_endpoint.h
fwp/libfwp/src/Makefile.omk
fwp/libfwp/src/fwp_endpoint.c
fwp/libfwp/src/fwp_vres.c

index a2b9ad3636f517a2125cf32c230994d3594feef0..25d34a31cba9232e0a0e3da4b403463213253bc5 100644 (file)
@@ -5,8 +5,10 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <pthread.h>
 
 #include "fwp_conf.h"
+#include "fwp_util.h"
 
 
 /**
  */
 struct fwp_endpoint{
        int type;
-       int node;
-       int port;
+       //int node; 
+       //int port;
        struct sockaddr_in addr;
        int sockd;
-}
+       int status;
+};
 
+int fwp_send_endpoint_create(int node, int port, struct fwp_endpoint *epoint);
+int fwp_receive_endpoint_create(int port, struct fwp_endpoint *epoint);
+int fwp_endpoint_destroy(struct fwp_endpoint *epoint);
+
+/*int fwp_endpoint_setqpolicy(struct fwp_endpoint *epoint, qpolicy);*/
 
 #endif /*_FWP_ENDPOINT_H */ 
index 8de47a173a39ee176743b6da6fd3eae6247cf3a1..a5bf6ca9e0dbe94d0b596157ef4c10152b03adba 100644 (file)
@@ -2,6 +2,6 @@ lib_LIBRARIES = fwp
 CFLAGS = -Wall -D_REENTRANT -g
 #LDFLAGS = -lpthread  -lrt
 fwp_SOURCES = fwp_util.c fwp_ac.c fwp_vres.c fwp_msgb.c fwp_msgq.c fwp_msg.c\
-             fwp_proto.c fwp_ctable.c 
+             fwp_proto.c fwp_ctable.c fwp_endpoint.c 
 
 #lib_LOADLIBES+= pthread rt
index 7331e193a687ed57f78962c1443a13a616cfd2ea..a6cb2d7e8e3cfd604035f85c3b41eea05bc53bc5 100644 (file)
@@ -2,7 +2,7 @@
 
 
 enum fwp_endpoint_type_t {
-       FWP_SEND_EPOIN = 0,
+       FWP_SEND_EPOINT = 0,
        FWP_RECV_EPOINT = 1,
 };
 
@@ -23,26 +23,21 @@ inline int fwp_endpoint_is_valid(int id)
        return 0;
 }
 
-void fwp_endpoint_table_init()
-{
+void fwp_endpoint_table_init(){
        int id;
 
        for (id = 0; id < FWP_EPOINT_MAX; id++) 
                fwp_endpoint_table[id].status = FWP_EPOINT_CLOSED;
 }
 
-struct fwp_endpoint* fwp_endpoint_create(int type, int node, int port)
-/* queueing policy should be the next parameter*/
+static struct fwp_endpoint* fwp_endpoint_alloc()
 {
-       int id,rc;
+       int id;
        struct fwp_endpoint *epoint;
        
-       /* Check for validity of the contract */
-#warning Wrong comments
-       /* obtain fwp_vres_table mutex */
-       pthread_mutex_lock(&fwp_epoint_table_lock);
+       pthread_mutex_lock(&fwp_endpoint_table_lock);
 
-       /* find free vres id */
+       /* find free endpoint */
        id = 0;
        while ((id < FWP_EPOINT_MAX) && 
                (fwp_endpoint_table[id].status != FWP_EPOINT_CLOSED)){ 
@@ -50,35 +45,66 @@ struct fwp_endpoint* fwp_endpoint_create(int type, int node, int port)
                id++;
        }
        if (id == FWP_EPOINT_MAX) {
-               /* release fwp_vres_table mutex */
-               return -ENOMEM;
+               pthread_mutex_unlock(&fwp_endpoint_table_lock);
+               return NULL;
        }
        
        epoint = &fwp_endpoint_table[id];
        epoint->status = FWP_EPOINT_OPENED;
-       /* release fwp_vres_table mutex */
+       
        pthread_mutex_unlock(&fwp_endpoint_table_lock);
+       
+       return epoint;
+}
 
+
+/**
+ * Creates endpoint
+ *
+ * \param type Specifies type of endpoint to create. The value FWP_SEND_EPOINT 
+ * stands for send endpoint. The value FWP_RECV_EPOINT stands for receive
+ * endpoint.
+ *
+ * \param node IP address of destination node in case of send endpoint; local
+ * IP 
+ */
+
+int fwp_send_endpoint_create(int node, int port, struct fwp_endpoint *epoint)
+{      
+       if (!(epoint = fwp_endpoint_alloc())) {
+               return -ENOMEM;
+       }
+       
        epoint->addr.sin_family = AF_INET;
+       epoint->addr.sin_addr.s_addr = node;
        epoint->addr.sin_port = htons(port);
-        if (type == FWP_SEND_EPOINT) {
-               epoint->addr.sin_addr.s_addr = node;
-               return epoint; 
-       }
+        epoint->type = FWP_SEND_EPOINT;
 
-       epoint->addr.sin_addr.s_addr = INADDR_ANY;
+       return 0; 
+}
+       
+int fwp_receive_endpoint_create(int port, struct fwp_endpoint *epoint)
+{
+       int rv;
 
-       if ((epoint->sockd = socket(AF_INET, SOCK_DGRAM, 0)) == -1){
-               perror("fwp_endpoint_create - socket error");
-               return (-errno);
+       if (!(epoint = fwp_endpoint_alloc())) {
+               return -ENOMEM;
        }
-               
-       if (bind(epoint->sockd, (struct sockaddr*) &epoint->addr, 
-                sizeof(epoint->addr)) == -1) {
-                       
-               perror("fwp_endpoint_create - bind error");
-               return (-errno);
+       
+       epoint->type = FWP_RECV_EPOINT;
+       rv = fwp_create_inet_socket(port, &epoint->addr);
+       if (rv) {
+               epoint->sockd = rv;
+               return 0;
+       }
+       else {
+               fwp_endpoint_destroy(epoint);   
+               return rv;
        }
-    
+}
 
+int fwp_endpoint_destroy(struct fwp_endpoint *epoint)
+{
+       epoint->status = FWP_EPOINT_CLOSED; 
+       return 0;
 }
index 5be7c89a10cf64f3d980687afe81bfe8e3f804e3..108bbb3f444582cefcce4f152fb81b71008af935 100644 (file)
@@ -71,6 +71,7 @@ int fwp_vres_open(struct fwp_contract *cnt)
        }
        if (id == FWP_VRES_MAX) {
                /* release fwp_vres_table mutex */
+               pthread_mutex_unlock(&vres_table_lock);
                return -ENOMEM;
        }