tClean peer list after processing - synk - synchronize files between hosts
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit e91bc489c877001d81332b0f1d26c41a54c572d9
DIR parent 37a972d5c8dfb078d5e9ad89642a7de7faa84b3d
HTML Author: Willy <willyatmailoodotorg>
Date: Fri, 26 Aug 2016 08:25:42 +0200
Clean peer list after processing
Diffstat:
M synk.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
---
DIR diff --git a/synk.c b/synk.c
t@@ -48,10 +48,11 @@ enum {
void usage(char *name);
long gettimestamp(const char *path);
+int getpeerinfo(struct metadata_t, struct node_t *);
+struct node_t *addpeer(in_addr_t, in_port_t);
+int cleanpeers();
void *handleclient(void *arg);
int server(in_addr_t, in_port_t);
-struct node_t *addpeer(in_addr_t, in_port_t);
-int getpeerinfo(struct metadata_t, struct node_t *);
int synkronize(FILE *, const char *fn);
SLIST_HEAD(head_node_t, node_t) head;
t@@ -203,6 +204,19 @@ addpeer(in_addr_t host, in_port_t port)
return entry;
}
+int
+cleanpeers()
+{
+ struct node_t *tmp = NULL;
+ while (!SLIST_EMPTY(&head)) {
+ tmp = SLIST_FIRST(&head);
+ SLIST_REMOVE_HEAD(&head, entries);
+ free(tmp);
+ }
+
+ return 0;
+}
+
/*
* Client part: connect to the given address/port and send the given path to
* the server. The server should return the timestamp for this file on the
t@@ -266,6 +280,8 @@ synkronize(FILE *f, const char *fn)
if (cmp == 0)
printf("%s\tSYNKED\n", local.path);
+ cleanpeers();
+
return 0;
}