[vhffs-dev] [1268] remplaced the 0x1F separator to single \0 as separator and double \0 as terminator , this is a bit daring ;-) |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [1268] remplaced the 0x1F separator to single \0 as separator and double \0 as terminator , this is a bit daring ;-)
- From: subversion@xxxxxxxxxxxxx
- Date: Tue, 07 Oct 2008 23:41:49 +0200
Revision: 1268
Author: gradator
Date: 2008-10-07 23:41:49 +0200 (Tue, 07 Oct 2008)
Log Message:
-----------
remplaced the 0x1F separator to single \0 as separator and double \0 as terminator, this is a bit daring ;-)
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-07 11:34:45 UTC (rev 1267)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2008-10-07 21:41:49 UTC (rev 1268)
@@ -25,9 +25,6 @@
#include <sys/sendfile.h>
-/* TODO: vérifier qu'un nom de fichier ne contient pas un \x1F, sinon c'est le segfault assuré du client */
-/* convertir les \x1F vers un espace lors de l'émission de l'évent ? */
-
/* -- inotify stuff -- */
#define VHFFSFSSYNC_BUF_LEN 4096
@@ -164,8 +161,11 @@
inline void vhffsfssync_net_destroy_message(vhffsfssync_conn *conn, vhffsfssync_net_message *msg);
int vhffsfssync_net_send_data(vhffsfssync_conn *conn, char *data, ssize_t len, uint32_t priority);
void vhffsfssync_net_destroy_data(vhffsfssync_conn *conn, vhffsfssync_net_message_data *datamsg);
-inline int vhffsfssync_net_send_string(vhffsfssync_conn *conn, char *data, uint32_t priority) ;
-void vhffsfssync_net_broadcast_string(char *data, uint32_t priority);
+//inline int vhffsfssync_net_send_string(vhffsfssync_conn *conn, char *data, uint32_t priority) ;
+inline ssize_t vhffsfssync_net_event_len(char *data);
+inline int vhffsfssync_net_send_event(vhffsfssync_conn *conn, char *data, uint32_t priority);
+//void vhffsfssync_net_broadcast_string(char *data, uint32_t priority);
+void vhffsfssync_net_broadcast_event(char *data, uint32_t priority);
int vhffsfssync_net_send_file(vhffsfssync_conn *conn, char *pathname);
void vhffsfssync_net_destroy_file(vhffsfssync_conn *conn, vhffsfssync_net_message_file *filemsg);
FILE *vhffsfssync_net_file_open(vhffsfssync_conn *conn, const char *pathname, const char *mode);
@@ -256,12 +256,28 @@
free(datamsg);
}
-
+/*
inline int vhffsfssync_net_send_string(vhffsfssync_conn *conn, char *data, uint32_t priority) {
return vhffsfssync_net_send_data(conn, data, strlen(data), priority);
}
+*/
+/* our events use \0 as a delimiter, a double \0 is the end of the event */
+inline ssize_t vhffsfssync_net_event_len(char *data) {
+ ssize_t len = 0;
+ do {
+ len += strlen(data+len); //glibc strlen() is incredibly fast, we use it as much as possible
+ len++;
+ } while( *(data+len) );
+ len++;
+ return len;
+}
+inline int vhffsfssync_net_send_event(vhffsfssync_conn *conn, char *data, uint32_t priority) {
+ return vhffsfssync_net_send_data(conn, data, vhffsfssync_net_event_len(data), priority);
+}
+
+/*
void vhffsfssync_net_broadcast_string(char *data, uint32_t priority) {
GList *conns;
@@ -273,8 +289,26 @@
}
free(data);
}
+*/
+void vhffsfssync_net_broadcast_event(char *data, uint32_t priority) {
+ GList *conns;
+ ssize_t len;
+ len = vhffsfssync_net_event_len(data);
+ for(conns = g_list_first(vhffsfssync_conns) ; conns ; ) {
+ vhffsfssync_conn *conn = conns->data;
+ char *d;
+ conns = g_list_next(conns);
+
+ d = malloc(len);
+ memcpy(d, data, len);
+ vhffsfssync_net_send_data(conn, d, len, priority);
+ }
+ free(data);
+}
+
+
// prototype is simple, files are always the lowest of the lowest priority messages
int vhffsfssync_net_send_file(vhffsfssync_conn *conn, char *pathname) {
vhffsfssync_net_message_file *msg;
@@ -305,7 +339,7 @@
// if the file is being sent, cancel it
vhffsfssync_net_remove_file(conn, pathname);
//printf("%d SENDING FILE %s\n", conn->fd, pathname);
- vhffsfssync_net_send_string( conn, g_strdup_printf("create\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("create%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
// the size of the file is the priority (small files are sent with more priority)
// but don't set the priority too low, low value can be used for anything else
@@ -507,7 +541,7 @@
filemsg->file_chunkcur = 0;
// we need to make sure that the chunk will not be truncated, we set the current message to the highest priority
msg->msg_priority = 1;
- vhffsfssync_net_send_string(conn, g_strdup_printf("write\x1F%s\x1F%lld\x1F%lld\n", filemsg->file_pathname, (long long int)filemsg->file_offset, (long long int)filemsg->file_chunksize) , 0);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("write%c%s%c%lld%c%lld%c", '\0', filemsg->file_pathname, '\0', (long long int)filemsg->file_offset, '\0', (long long int)filemsg->file_chunksize, '\0') , 0);
// we need to reset here in order to consider the new priorities
continue;
}
@@ -793,7 +827,7 @@
vhffsfssync_conn *conn = conns->data;
conns = g_list_next(conns);
vhffsfssync_net_remove_file(conn, pathname);
- vhffsfssync_net_send_string(conn, g_strdup_printf("remove\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("remove%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
return 0;
}
@@ -808,7 +842,7 @@
#if DEBUG_INOTIFY
printf("==> CREATE %s\n", pathname);
#endif
- vhffsfssync_net_broadcast_string( g_strdup_printf("create\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("create%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
if(sendfile && st.st_size > 0) {
vhffsfssync_net_broadcast_file(pathname);
}
@@ -819,7 +853,7 @@
printf("==> MKDIR %s\n", pathname);
#endif
vhffsfssync_add_watch(inotifyfd, pathname, VHFFSFSSYNC_WATCH_MASK);
- vhffsfssync_net_broadcast_string( g_strdup_printf("mkdir\x1F%s\n", pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("mkdir%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
/* there is a short delay between the mkdir() and the add_watch(),
we need to send events about the data which have already been written */
vhffsfssync_fake_events_recursively( inotifyfd, pathname );
@@ -835,7 +869,7 @@
#if DEBUG_INOTIFY
printf("==> SYMLINK %s -> %s\n", pathname, linkto);
#endif
- vhffsfssync_net_broadcast_string( g_strdup_printf("symlink\x1F%s\x1F%s\n", pathname, linkto) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("symlink%c%s%c%s%c", '\0', pathname, '\0', linkto, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
free(linkto);
if(ret < 0) {
@@ -979,7 +1013,7 @@
if( vhffsfssync_cookie.isdir )
vhffsfssync_modify_watch(inotifyfd, vhffsfssync_cookie.from, pathname);
- vhffsfssync_net_broadcast_string( g_strdup_printf("move\x1F%s\x1F%s\n", vhffsfssync_cookie.from, pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("move%c%s%c%s%c", '\0', vhffsfssync_cookie.from, '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_cookie.id = 0;
free(vhffsfssync_cookie.from);
}
@@ -1255,7 +1289,7 @@
#if DEBUG_NET
printf("Welcome %s ! (using fd %d)\n", inet_ntoa(conn->sockaddr.sin_addr), conn->fd);
#endif
- vhffsfssync_net_send_string(conn, strdup("hello\n"), VHFFSFSSYNC_NET_PRIO_HIGHEST);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("hello%c", '\0') , VHFFSFSSYNC_NET_PRIO_HIGHEST);
/*
grosbuf=malloc(10485760);
memset(grosbuf, 'A', 10485760);
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-07 11:34:45 UTC (rev 1267)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-07 21:41:49 UTC (rev 1268)
@@ -131,16 +131,11 @@
int argc;
argc = 0;
- cur = event;
- while(*cur != '\0' && argc < 10) {
- for( ; *cur != '\x1F' && *cur != '\0' ; cur++ );
+ do {
+ for(cur = event ; *cur++ != '\0' ; );
args[argc++] = event;
- if( *cur == '\x1F' ) {
- *cur = '\0';
- event = ++cur;
- }
- }
-
+ event = cur;
+ } while(*event && argc < 10);
if(!argc) return -1;
#if DEBUG_EVENTS
@@ -245,12 +240,12 @@
// text mode
if(!conn->chunk_stilltoread) {
char *begin;
- for(begin = cur ; cur < end && *cur != '\n' ; cur++ );
+ // find "\0\0"
+ for(begin = cur ; ( cur < end && *cur++ != '\0' ) || ( cur < end && *cur++ != '\0' ) ; );
- if( *cur == '\n' ) {
- *cur = '\0';
+ if( !*(cur-2) && !*(cur-1) ) {
vhffsfssync_event(conn, begin);
- begin = ++cur;
+ begin = cur;
}
if(cur == end) {