]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Adding more comments to fwp_endpoint
authorMartin Molnar <molnam1@fel.cvut.cz>
Sun, 26 Oct 2008 00:02:48 +0000 (02:02 +0200)
committerMartin Molnar <molnam1@fel.cvut.cz>
Sun, 26 Oct 2008 11:24:21 +0000 (12:24 +0100)
fwp/lib/core/fwp_endpoint.c
fwp/lib/core/fwp_endpoint.h

index ee031440829c329d9c9fb4ee5526724ac72906da..d9d87547c53d3d67168088725ab07f3dbdf9a04e 100644 (file)
@@ -6,34 +6,42 @@
 
 typedef unsigned int fwp_endpoint_id_t;
 
+/**
+ * Default fwp endpoint attributes
+ */
 static fwp_endpoint_attr_t fwp_epoint_attr_default ={
        .reliability = FWP_EPOINT_BESTEFFORT, 
        .max_connections = 20,
 };
 
 /**
- * Structure of FWP endpoint.
+ * FWP endpoint structure
  */
 struct fwp_endpoint{
-       /** endpoint attributes */
+       /** Fwp endpoint attributes */
        fwp_endpoint_attr_t     attr;
-       /** for send enpoint it contains destination address for
+       /** For send enpoint it contains destination address for
         * receive endpoint it is filled with the msg source address
         */
-       fwp_vres_d_t            vresd;
        struct fwp_sockaddr     peer;   
-       /** source/destination port */
+       /** Dource/destination port */
        unsigned int            port;   
-       /** destination node */
+       /** Destination node */
        int                     node;
        /** Socket descriptor.
-        * In case of rebliable epoint it is a listen socket.
-        * */
+        * In case of rebliable epoint it is a listen tcp socket.
+        */
        int                     sockd; 
-       fd_set                  fdset;
-       fd_set                  testfds;
+       /** File descriptor array of peers connected 
+        * to this fwp receive endpoint.*/
        int                     *c_sockd;
+       /**
+        * Number of connections 
+        */
        unsigned int            nr_connections;
+       /** client fdset */
+       fd_set                  fdset;
+       fd_set                  testfds;
        /** specific operation options*/
        int                     flags;  
 };
@@ -41,7 +49,7 @@ struct fwp_endpoint{
 /**
  * Allocates endpoint
  *
- * \return On success returns endpoint structure. 
+ * \return On success returns fwp endpoint structure. 
  * On error, NULL is returned. 
  *
  */
@@ -122,7 +130,7 @@ int fwp_endpoint_attr_init(fwp_endpoint_attr_t *attr)
 int fwp_send_endpoint_create(unsigned int node,
                                unsigned int port, 
                                fwp_endpoint_attr_t *attr,
-                               fwp_endpoint_t **epoint)
+                               fwp_endpoint_d_t *epointp)
 {      
        struct sockaddr_in *addr;
        fwp_endpoint_t *fwp_epoint;
@@ -187,7 +195,7 @@ int fwp_send_endpoint_create(unsigned int node,
        }
 #endif
        
-       *epoint = fwp_epoint;
+       *epointd = fwp_epoint;
        return 0;               
 err:
        fwp_endpoint_destroy(fwp_epoint);
@@ -205,7 +213,7 @@ err:
  */
 int fwp_receive_endpoint_create(unsigned int port,
                                fwp_endpoint_attr_t *attr,
-                               fwp_endpoint_t **epoint)
+                               fwp_endpoint_d_t *epointd)
 {
        struct sockaddr_in *addr;
        fwp_endpoint_t *fwp_epoint;
@@ -227,7 +235,7 @@ int fwp_receive_endpoint_create(unsigned int port,
        addr = (struct sockaddr_in *) &(fwp_epoint->peer.addr);
        addr->sin_family = AF_INET;
        /* TODO: set listen interface, maybe through config struct*/
-       addr->sin_addr.s_addr = INADDR_ANY;
+       addr->sin_addr.s_addr = FWP_ANY_NODE;
        fwp_epoint->port  = addr->sin_port = htons(port);
         fwp_epoint->peer.addrlen = sizeof(struct sockaddr_in);
        
@@ -299,7 +307,7 @@ int fwp_receive_endpoint_create(unsigned int port,
        getsockname(fwp_epoint->sockd, (struct sockaddr*)&fwp_epoint->peer.addr, 
                        &fwp_epoint->peer.addrlen);
        
-       *epoint = fwp_epoint;   
+       *epointd = fwp_epoint;  
        return 0;
 err:
        fwp_endpoint_destroy(fwp_epoint);
@@ -314,10 +322,10 @@ err:
  *
  * \return On success returns 0. On error, -1 and errno is set appropriately.
  */
-int fwp_send_endpoint_bind(fwp_endpoint_t *epoint, fwp_vres_d_t vresd)
+int fwp_send_endpoint_bind(fwp_endpoint_d_t epointd, fwp_vres_d_t vresd)
 {
        int rv;
-       fwp_endpoint_t *fwp_epoint = epoint;
+       fwp_endpoint_t *fwp_epoint = epointd;
        
 #ifndef FWP_CONTNEGT
        FWP_DEBUG("Empty bind\n");
@@ -340,10 +348,10 @@ int fwp_send_endpoint_bind(fwp_endpoint_t *epoint, fwp_vres_d_t vresd)
  * \return On success returns 0. On error, -1 is returned and errno is set appropriately.
  *
  */
-int fwp_send_endpoint_unbind(fwp_endpoint_t *epoint)
+int fwp_send_endpoint_unbind(fwp_endpoint_d_t epointd)
 {
        int rv = 0;
-       fwp_endpoint_t *fwp_epoint = epoint;
+       fwp_endpoint_t *fwp_epoint = epointd;
 
        /* unlink epoint-vres mutually */
        if ((rv = fwp_vres_unbind(fwp_epoint->vresd)) < 0) 
@@ -352,6 +360,14 @@ int fwp_send_endpoint_unbind(fwp_endpoint_t *epoint)
        return 0;
 }
 
+/**
+ * Accepts (TCP) client connection to receive endpoint
+ *
+ * \param[in] epointd Pointer to fwp endpoint
+ * \return
+ * On success, it returns zero.  
+ *
+ */
 static int fwp_receive_endpoint_accept(fwp_endpoint_t *fwp_epoint)
 {
        int csockd;
@@ -377,12 +393,9 @@ static int fwp_receive_endpoint_accept(fwp_endpoint_t *fwp_epoint)
        while ((fwp_epoint->c_sockd[i])&& (i < fwp_epoint->nr_connections)) 
                                i++;
        fwp_epoint->c_sockd[i] = csockd; 
-       FWP_DEBUG("Index = %d\n", i);
        fwp_epoint->nr_connections++;
                
-       FWP_DEBUG("before\n");
        FD_SET(csockd, &fwp_epoint->fdset);
-       FWP_DEBUG("SET fdset\n");
        return 0;       
 } 
 
@@ -448,14 +461,14 @@ int fwp_recv_conn(fwp_endpoint_d_t epointd, void *buffer,
  * On error, -1 is returned and errno is set appropriately.
  *
  */
-ssize_t fwp_recv(fwp_endpoint_t *endpoint,
+ssize_t fwp_recv(fwp_endpoint_d_t epointd,
                        void *buffer, const size_t buffer_size,
                        unsigned int *from, int flags)
 {
-       fwp_sockaddr_t *peer = &endpoint->peer;
+       fwp_endpoint_t *fwp_epoint = epointd;
+       fwp_sockaddr_t *peer = &fwp_epoint->peer;
        ssize_t len;
        fd_set fdset;
-       fwp_endpoint_t *fwp_epoint = endpoint;
        
 /*     if (!fwp_endpoint_is_valid(epointd)) {
                errno = EINVAL;
@@ -503,10 +516,11 @@ ssize_t fwp_recv(fwp_endpoint_t *endpoint,
  * On error, -1 is returned and errno is set appropriately.
  *
  */
-int fwp_send(fwp_endpoint_t *fwp_epoint,const void *msg, const size_t size, int flags)
+int fwp_send(fwp_endpoint_d_t *epointd,const void *msg, const size_t size, 
+               int flags)
 {
+       fwp_endpoint_t *fwp_epoint = epointd;
        struct fwp_msgb *msgb;
-       /*fwp_endpoint_t *fwp_epoint;*/
        
 /*     if (!fwp_endpoint_is_valid(epointd)){
                errno = EINVAL;
index 9be8db069beb36dcdd04bee7671a54730f68084d..531534080eacc67374142e0a676813a993b2659b 100644 (file)
@@ -20,7 +20,9 @@ typedef unsigned int fwp_addr_t;
  */
 typedef
 struct fwp_endpoint_attr {
+       /** Specifies whether fwp enpoint is reliable (TCP) or not (UDP)*/
        unsigned int reliability;
+       /** Specifies max number of allowed connections */
        unsigned int max_connections;
        /* queueing policy*/
 } fwp_endpoint_attr_t;
@@ -33,20 +35,20 @@ int fwp_endpoint_get_params(fwp_endpoint_d_t epointd, unsigned int *node,
                                unsigned int *port, fwp_endpoint_attr_t *attr);
 int fwp_send_endpoint_create(unsigned int node, unsigned int port,
                                fwp_endpoint_attr_t *attr, 
-                               fwp_endpoint_t **epoint);
+                               fwp_endpoint_d_t *epointd);
 int fwp_receive_endpoint_create(/*unsigned int node,*/ unsigned int port,
                                fwp_endpoint_attr_t *attr, 
-                               fwp_endpoint_t **epoint);
+                               fwp_endpoint_d_t *epointd);
 int fwp_endpoint_destroy(fwp_endpoint_d_t epointd);
 
 int fwp_send_endpoint_bind(fwp_endpoint_d_t epointd, fwp_vres_d_t vresd);
 int fwp_send_endpoint_unbind(fwp_endpoint_d_t epointd);
 
-ssize_t fwp_recv(fwp_endpoint_t *endpoint,
+ssize_t fwp_recv(fwp_endpoint_d_t epointd,
                        void *buffer, const size_t buffer_size,
                        unsigned int *from, int flags);
-int fwp_send(fwp_endpoint_t *fwp_epoint, const void *msg, const size_t size, int flags);
-
+int fwp_send(fwp_endpoint_d_t epointd, const void *msg, const size_t size, 
+               int flags);
 int fwp_endpoint_attr_init(fwp_endpoint_attr_t *attr);
 
 static inline int fwp_endpoint_attr_setreliability(fwp_endpoint_attr_t *attr,