[vhffs-dev] [1281] The slave now checks that it is synchronized with the master. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1281
Author: gradator
Date: 2008-10-13 21:54:56 +0200 (Mon, 13 Oct 2008)
Log Message:
-----------
The slave now checks that it is synchronized with the master.
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
trunk/vhffs-fssync/vhffsfssync_slave.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2008-10-13 19:26:24 UTC (rev 1280)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2008-10-13 19:54:56 UTC (rev 1281)
@@ -25,7 +25,6 @@
#include <netinet/in.h>
#include <sys/sendfile.h>
-/* TODO: timestamp check */
/* -- inotify stuff -- */
@@ -800,6 +799,11 @@
}
*/
}
+ else if(!strcmp(args[0], "time")) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("time%c%ld%c", '\0', tv.tv_sec, '\0') , VHFFSFSSYNC_NET_PRIO_HIGH);
+ }
else if(!strcmp(args[0], "hello")) {
// nice to meet you
}
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-13 19:26:24 UTC (rev 1280)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-13 19:54:56 UTC (rev 1281)
@@ -312,6 +312,7 @@
int vhffsfssync_event(vhffsfssync_conn *conn, char *event) {
char *cur, **args = NULL;
int argalloc = 0, argc = 0;
+ int ret = 0;
do {
for(cur = event ; *cur++ != '\0' ; );
@@ -446,16 +447,26 @@
}
free(root_);
}
+ else if(!strcmp(args[0], "time")) {
+ time_t sec;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ sec = atol(args[1]);
+ if( abs(tv.tv_sec - sec) > 10 ) {
+ fprintf(stderr, "The slave timestamp is not synchronous with the master timestamp\n");
+ ret = -1;
+ }
+ }
else if(!strcmp(args[0], "hello")) {
// nice to meet you
}
else {
fprintf(stderr, "Received unhandled event: %s\n", args[0]);
- exit(1);
+ ret = -1;
}
free(args);
- return 0;
+ return ret;
}
@@ -477,7 +488,8 @@
for(begin = cur ; ( cur < end && *cur++ != '\0' ) || ( cur < end && *cur++ != '\0' ) ; );
if( !*(cur-2) && !*(cur-1) ) {
- vhffsfssync_event(conn, begin);
+ if( vhffsfssync_event(conn, begin) )
+ return -1;
conn->recvbuf_begin += (cur - begin);
begin = cur;
}
@@ -636,6 +648,7 @@
/* connected */
vhffsfssync_net_send_event(conn, g_strdup_printf("hello%c", '\0') );
+ vhffsfssync_net_send_event(conn, g_strdup_printf("time%c", '\0') );
vhffsfssync_net_send_event(conn, g_strdup_printf("fulltree%c", '\0') );
/* -- the real main loop starts here -- */