]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Fixing bugs related to tcp tranfer. Still not working
authorMartin <molnam1@fel.cvut.cz>
Tue, 21 Oct 2008 17:11:06 +0000 (19:11 +0200)
committerMartin <molnam1@fel.cvut.cz>
Tue, 21 Oct 2008 17:11:06 +0000 (19:11 +0200)
fwp/lib/Makefile.omk
fwp/lib/core/fwp_endpoint.c
fwp/lib/core/tests/Makefile.omk
fwp/lib/core/tests/fwp_msgtest/Makefile.omk
fwp/lib/core/tests/fwp_prototest/Makefile [moved from fwp/tests/fwp_prototest/Makefile with 100% similarity]
fwp/lib/core/tests/fwp_prototest/Makefile.omk [moved from fwp/tests/fwp_prototest/Makefile.omk with 100% similarity]
fwp/lib/core/tests/fwp_prototest/fwp_sendrecv_test1.c [moved from fwp/tests/fwp_prototest/fwp_sendrecv_test1.c with 96% similarity]
fwp/lib/core/tests/fwp_prototest/fwp_sendrecv_test2.c [moved from fwp/tests/fwp_prototest/fwp_sendrecv_test2.c with 91% similarity]
fwp/lib/core/tests/fwp_vrestest/Makefile.omk
fwp/lib/core/tests/fwp_vrestest/fwp_vrestest1.c

index 4c39041fb5100a4dfefda30f8637a287d2328248..c1f7401dc8fa0f7f4c9b8db0a51987a791de6038 100644 (file)
@@ -1,4 +1,4 @@
-shared_LIBRARIES = fwp
+lib_LIBRARIES = fwp
 CFLAGS += -D_FWP_INTERNALS_
 SUBDIRS = core  
 #LDFLAGS = -lpthread  -lrt
@@ -12,5 +12,4 @@ include_HEADERS= fwp_conf.h fwp_confdefs.h fwp_fna.h fwp.h
 
 #include_HEADERS=  fwp_vres.h fwp_msgb.h fwp_msgq.h \
                  fwp_conf.h  fwp_util.h fwp_endpoint.h fwp.h 
-lib_LOADLIBES+= pthread ulut fna 
-#lib_LOADLIBES+= pthread rt
+lib_LOADLIBES+= pthread rt ulut fna 
index 95449a4df6340ca61da667b5ffabda16d281ea31..79c53f7a977267f65575b29373e89104d4c84cff 100644 (file)
@@ -216,7 +216,7 @@ int fwp_receive_endpoint_create(unsigned int port,
        else
                fwp_epoint->attr = fwp_epoint_attr_default;
 
-       addr = (struct sockaddr_in *)&(fwp_epoint->peer.addr);
+       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;
@@ -244,7 +244,10 @@ int fwp_receive_endpoint_create(unsigned int port,
                        goto err;
                }
                
-               listen(fwp_epoint->sockd, fwp_epoint->attr.max_connections); 
+               if (listen(fwp_epoint->sockd, fwp_epoint->attr.max_connections)){
+                       perror("Error on listen call\n");
+                       goto err;
+               }
                
                FD_ZERO(&fwp_epoint->fdset);
                /*add listen socket */
@@ -255,8 +258,8 @@ int fwp_receive_endpoint_create(unsigned int port,
                bzero(fwp_epoint->c_sockd, fwp_epoint->attr.max_connections);
                fwp_epoint->nr_connections = 0;
 
-               FWP_DEBUG("Receive endpoint\n");
-
+               FWP_DEBUG("Reliable receive endpoint port=%d created.\n", 
+                               fwp_epoint->port); 
        } else {
                if ((fwp_epoint->sockd = socket(PF_INET, SOCK_DGRAM, 
                                                IPPROTO_UDP)) < 0) {
@@ -271,6 +274,8 @@ int fwp_receive_endpoint_create(unsigned int port,
                        FWP_ERROR("Bind error: %s", strerror(errno));
                        goto err;
                }
+               FWP_DEBUG("Best-Effort receive endpoint port=%d created.\n", 
+                               fwp_epoint->port); 
        }
                
        /*if (setsockopt(epoint->sockd, SOL_SOCKET, SO_RCVBUF, 
@@ -286,12 +291,11 @@ int fwp_receive_endpoint_create(unsigned int port,
        getsockname(fwp_epoint->sockd, (struct sockaddr*)&fwp_epoint->peer.addr, 
                        &fwp_epoint->peer.addrlen);
        
-       FWP_DEBUG("Receive endpoint port=%d created.\n", fwp_epoint->port); 
        *epoint = fwp_epoint;   
        return 0;
 err:
        fwp_endpoint_destroy(fwp_epoint);
-       return -1;
+       return errno;
 }
 
 /**
@@ -336,19 +340,25 @@ int fwp_send_endpoint_unbind(fwp_endpoint_t *epoint)
        return 0;
 }
 
-int fwp_receive_endpoint_accept(fwp_endpoint_d_t epointd)
+static int fwp_receive_endpoint_accept(fwp_endpoint_t *fwp_epoint)
 {
        int csockd;
-       fwp_endpoint_t *fwp_epoint = epointd;
+//     fwp_endpoint_t *fwp_epoint = epointd;
        fwp_sockaddr_t  peer;
        int i;
 
        if (fwp_epoint->nr_connections == fwp_epoint->attr.max_connections)
                return -1;
 
+       peer.addrlen = sizeof(struct sockaddr_in);
        csockd = accept(fwp_epoint->sockd, (struct sockaddr*)peer.addr,
                        &peer.addrlen);
-               
+       
+       if (csockd < 0) {
+               perror("Error on accept\n");
+               return errno;   
+       }               
+
        FWP_DEBUG("New connection accepted\n");
        /* find free place */           
        i = 0;
@@ -358,7 +368,9 @@ int fwp_receive_endpoint_accept(fwp_endpoint_d_t epointd)
        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;       
 } 
 
@@ -388,6 +400,7 @@ int fwp_recv_conn(fwp_endpoint_d_t epointd, void *buffer,
                        continue;       
                }       
                        
+               peer->addrlen = sizeof(struct sockaddr_in);
                len = _fwp_recvfrom(fwp_epoint->c_sockd[i], buffer, 
                                        buffer_size,0, peer);
 
@@ -453,7 +466,8 @@ ssize_t fwp_recv(fwp_endpoint_t *endpoint,
                }
        
                if (FD_ISSET(fwp_epoint->sockd, &fdset)) { /* is it listen socket? */
-                       fwp_receive_endpoint_accept(endpoint);
+                       fwp_receive_endpoint_accept(fwp_epoint);
+                       FWP_DEBUG("After accepted\n");
                        continue;
                }
 
index e02562003678be46b49f0bd2ed3072371e564ee1..23147ae2f494e639ad08686c9bc500ad397b46c8 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS= fwp_msgtest fwp_vrestest 
+SUBDIRS= fwp_msgtest fwp_vrestest fwp_prototest 
 #fwp_prototest fwp_mngrtest  
 #SUBDIRS= fwp_msgtest fwp_vrestest fwp_prototest fwp_mngrtest  
 #fwp_mngrtest unixsocktest
index 559d9ad88b09e172f764d3c0f7fbaf63a8c27194..fbddba002a2a7a08c4f54917af41f8e49d323a9a 100644 (file)
@@ -1,4 +1,4 @@
 test_PROGRAMS = fwp_msgtest
 CFLAGS+= -D_FWP_INTERNALS_
 fwp_msgtest_SOURCES+= fwp_msgtest.c
-lib_LOADLIBES += fwp pthread 
+lib_LOADLIBES += pthread rt fwp
similarity index 96%
rename from fwp/tests/fwp_prototest/fwp_sendrecv_test1.c
rename to fwp/lib/core/tests/fwp_prototest/fwp_sendrecv_test1.c
index 1bbe9c0e885de7685e9d059e549159b1ff95d268..19f4cd9b20aa6d31f2de48bd2b9f2c7b3e914454 100644 (file)
@@ -29,6 +29,7 @@ int main()
        char buffer[30];
        fwp_endpoint_d_t sepoint_d1, sepoint_d2, repoint_d1, repoint_d2;
        fwp_endpoint_attr_t attr;
+       fwp_addr_t from;
        
        fwp_endpoint_attr_init(&attr);
 
@@ -85,7 +86,8 @@ int main()
        fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
 
        for (i = 0; i < 2; i++) {
-               if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), 0)) < 0) {
+               if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), &from, 
+                       0)) < 0) {
                        perror("Error while receiving data");
                        return -1;
                } 
similarity index 91%
rename from fwp/tests/fwp_prototest/fwp_sendrecv_test2.c
rename to fwp/lib/core/tests/fwp_prototest/fwp_sendrecv_test2.c
index 233f4d07cf87dc37775ee1d368def60e98cf4126..f905d3d26ded991340ad2fd80614f0126ff0e249 100644 (file)
@@ -25,6 +25,7 @@ void* receiver(void* arg)
        fwp_endpoint_d_t repoint_d1;
        int i,len;
        char buffer[30];
+       fwp_addr_t from;
        
        FWP_DEBUG("Creating receive endpoint\n");
        if (fwp_receive_endpoint_create(7777, &attr,&repoint_d1) < 0){
@@ -34,7 +35,8 @@ void* receiver(void* arg)
                
        FWP_DEBUG("Receive endpoint created \n");
        for (i = 0; i < 3; i++) {
-               if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), 0)) < 0) {
+               if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), &from,
+                        0)) < 0) {
                        perror("Error while receiving data::");
                        return NULL;
                } else {
@@ -56,7 +58,7 @@ int main()
        char msg1[] = "Hello1";
        char msg2[] = "Hello2";
        fwp_endpoint_d_t sepoint_d1;
-       pthread_t id;
+       pthread_t thread;
        
        vparam1.ac_id = FWP_AC_VO; 
        vparam1.budget = 100;
@@ -75,7 +77,7 @@ int main()
        fwp_endpoint_attr_init(&attr);
        fwp_endpoint_attr_setreliability(&attr, FWP_EPOINT_RELIABLE);
        
-       pthread_create(&id, NULL, &receiver, (void*) NULL);
+       pthread_create(&thread, NULL, &receiver, (void*) NULL);
        printf("Create vres1, vres2\n");
        if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
                printf("Unable to create vres1\n");
@@ -94,7 +96,8 @@ int main()
        FWP_DEBUG("Sent msg1\n");
        fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
        FWP_DEBUG("Sent msg2\n");
-
+       
+       pthread_join(thread, (void**) NULL);    
        /*if (fwp_vres_destroy(vres_d1) < 0) {
                perror("Unable to destroy vres1\n");
                return -1;
index d631f497e27835f99429c24feb68052877553cb1..b8ca4a162845a2be9a6d6f51aafcd0054ab79a4c 100644 (file)
@@ -2,4 +2,4 @@ test_PROGRAMS = fwp_vrestest1  fwp_vrestest2
 CFLAGS+= -D_FWP_INTERNALS_
 fwp_vrestest1_SOURCES+= fwp_vrestest1.c
 fwp_vrestest2_SOURCES+= fwp_vrestest2.c
-lib_LOADLIBES += fwp pthread rt ulut 
+lib_LOADLIBES += fwp pthread rt ulut  
index e5efad98b25d30ffe1166654b211819819098193..b0055a78586776462c5aefe515eff0b11223a621 100644 (file)
@@ -30,10 +30,11 @@ int main()
        fwp_endpoint_d_t sepoint_d1, repoint_d;
        int count;
        struct timespec  sendtime;
-       fwp_endpoint_attr_t attr ;
+       fwp_endpoint_attr_t attr;
        unsigned int from;
        
        fwp_endpoint_attr_init(&attr);
+
        vparam1.ac_id = FWP_AC_VO; 
        vparam1.budget = 100;
        vparam1.period_usec = 2111111;