Extract tiger.[ch] and utils.[ch] as common code.
[doldaconnect.git] / daemon / fnet-dc.c
index b3b9afe..175563b 100644 (file)
@@ -44,7 +44,7 @@
 #include "transfer.h"
 #include "sysevents.h"
 #include "net.h"
-#include "tiger.h"
+#include <tiger.h>
 
 /*
  * The Direct Connect protocol is extremely ugly. Thus, this code must
@@ -158,6 +158,7 @@ static struct dcexppeer *expected = NULL;
 static char *hmlistname = NULL;
 static char *xmllistname = NULL;
 static char *xmlbz2listname = NULL;
+static struct timer *listwritetimer = NULL;
 
 static void peerconnect(struct socket *sk, int err, struct fnetnode *fn);
 static void freedcpeer(struct dcpeer *peer);
@@ -168,6 +169,7 @@ static void updatehmlist(void);
 static void updatexmllist(void);
 static void updatexmlbz2list(void);
 static void requestfile(struct dcpeer *peer);
+static void updatelists(int now);
 
 static int reservedchar(unsigned char c)
 {
@@ -3512,11 +3514,33 @@ static void updatexmlbz2list(void)
     fclose(real);
 }
 
-static int shareupdate(unsigned long long uusharesize, void *data)
+static void listtimercb(int cancelled, void *uudata)
+{
+    listwritetimer = NULL;
+    if(!cancelled)
+       updatelists(1);
+}
+
+static void updatelists(int now)
 {
+    if((hmlistname == NULL) || (xmllistname == NULL) || (xmlbz2listname == NULL))
+       now = 1;
+    if(!now)
+    {
+       if(listwritetimer == NULL)
+           listwritetimer = timercallback(ntime() + 300, listtimercb, NULL);
+       return;
+    }
+    if(listwritetimer != NULL)
+       canceltimer(listwritetimer);
     updatehmlist();
     updatexmllist();
     updatexmlbz2list();
+}
+
+static int shareupdate(unsigned long long uusharesize, void *data)
+{
+    updatelists(0);
     return(0);
 }