minor
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 3 Nov 2009 10:30:48 +0000 (10:30 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 3 Nov 2009 10:30:48 +0000 (10:30 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@494 e16421f0-f15b-0410-abcd-98678b794739

datagram.cpp
datagram.h
p2tp.cpp
p2tp.h

index c3ba032..3c07bd4 100644 (file)
@@ -14,7 +14,6 @@
 #else
     #include <arpa/inet.h>
 #endif
-//#define RND_DROP 10
 #include <glog/logging.h>
 #include "datagram.h"
 
@@ -23,6 +22,8 @@ namespace p2tp {
 tint Datagram::now = Datagram::Time();
 tint Datagram::epoch = now;
 uint32_t Datagram::Address::LOCALHOST = INADDR_LOOPBACK;
+uint64_t Datagram::dgrams_up=0, Datagram::dgrams_down=0, 
+         Datagram::bytes_up=0, Datagram::bytes_down=0;
 
 char* Datagram::TimeStr (tint time) {
     static char ret_str[128];
@@ -43,17 +44,12 @@ char* Datagram::TimeStr (tint time) {
 }
     
 int Datagram::Send () {
-#ifdef RND_DROP
-    if (rand()%RND_DROP==0) {
-        Time();
-        dprintf("%s datagram killed\n",TimeStr());
-        return size();
-    }
-#endif
        int r = sendto(sock,(const char *)buf+offset,length-offset,0,
                                   (struct sockaddr*)&(addr.addr),sizeof(struct sockaddr_in));
        //offset=0;
        //length=0;
+    dgrams_up++;
+    bytes_up+=size();
        Time();
        return r;
 }
@@ -69,13 +65,14 @@ int Datagram::Recv () {
 #else
                PLOG(ERROR)<<"on recv";
 #endif
+    dgrams_down++;
+    bytes_down+=length;
        Time();
        return length;
 }
 
 
 SOCKET Datagram::Wait (int sockcnt, SOCKET* sockets, tint usec) {
-       dprintf("waiting (%i socks)\n",sockcnt);
        struct timeval timeout;
        timeout.tv_sec = usec/TINT_SEC;
        timeout.tv_usec = usec%TINT_SEC;
index 63dae17..d272558 100644 (file)
@@ -97,6 +97,7 @@ struct Datagram {
     static char* TimeStr(tint time=0);
        static SOCKET Wait (int sockcnt, SOCKET* sockets, tint usec=0);
        static tint now, epoch;
+    static uint64_t dgrams_up, dgrams_down, bytes_up, bytes_down;
 
        Datagram (SOCKET socket, const Address addr_) : addr(addr_), offset(0),
                length(0), sock(socket) {}
index fd0e8b1..75692d1 100644 (file)
--- a/p2tp.cpp
+++ b/p2tp.cpp
@@ -77,9 +77,10 @@ int     p2tp::Listen (Datagram::Address addr) {
 
 void    p2tp::Shutdown (int sock_des) {
     for(int i=0; i<Channel::socket_count; i++)
-        if (Channel::sockets[i]==sock_des)
+        if (sock_des==-1 || Channel::sockets[i]==sock_des) {
+            Datagram::Close(Channel::sockets[i]);
             Channel::sockets[i] = Channel::sockets[--Channel::socket_count];
-    Datagram::Close(sock_des);
+        }
 }
 
 
diff --git a/p2tp.h b/p2tp.h
index 39b8bee..460a66a 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -360,7 +360,7 @@ namespace p2tp {
     /** Run send/receive loop for the specified amount of time. */
     void    Loop (tint till);
     /** Stop listening to a port. */
-    void    Shutdown (int sock_des);
+    void    Shutdown (int sock_des=-1);
 
     /** Open a file, start a transmission; fill it with content for a given root hash;
         in case the hash is omitted, the file is a fresh submit. */