[vhffs-dev] [1278] Replaced the linked list to a "slippery" dynamically allocated buffer for the send queue. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1278
Author: gradator
Date: 2008-10-13 19:08:31 +0200 (Mon, 13 Oct 2008)
Log Message:
-----------
Replaced the linked list to a "slippery" dynamically allocated buffer for the send queue. No more linked lists on the slave \o/
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 16:15:31 UTC (rev 1277)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2008-10-13 17:08:31 UTC (rev 1278)
@@ -220,6 +220,16 @@
}
conn->fullviewtree = g_list_delete_link(conn->fullviewtree, lst);
}
+
+ if(conn->delayedevents) {
+ uint32_t i;
+ for(i = conn->delayedevents_begin ; i < conn->delayedevents_end ; i++)
+ free(conn->delayedevents[i]);
+ free(conn->delayedevents);
+ }
+ conn->delayedevents = NULL;
+ conn->delayedevents_begin = 0;
+ conn->delayedevents_end = 0;
}
@@ -815,7 +825,7 @@
vhffsfssync_net_recv_event(conn, begin);
}
else {
- // system is overloaded, queue this event in delayed events
+ // system is overloaded, queue this event in delayed events
if( !(conn->delayedevents_end & 0x03FF) ) {
//printf("==> %d events, %d allocated\n", conn->delayedevents_end, ( (conn->delayedevents_end >>10) +1) <<10);
conn->delayedevents = realloc( conn->delayedevents, (((conn->delayedevents_end >>10) +1) <<10) * sizeof(char*) );
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-13 16:15:31 UTC (rev 1277)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2008-10-13 17:08:31 UTC (rev 1278)
@@ -30,6 +30,12 @@
#define VHFFSFSSYNC_NET_RECV_BUF_LEN 20971520
typedef struct {
+ char *data_buffer;
+ ssize_t data_len;
+ ssize_t data_cur;
+} vhffsfssync_net_message;
+
+typedef struct {
int fd;
struct sockaddr_in sockaddr;
@@ -40,17 +46,11 @@
FILE *chunk_file;
size_t chunk_stilltoread;
- /* TODO: replace this linked list to a "slippery" dynamically allocated buffer */
- GList *messages;
+ vhffsfssync_net_message **messages;
+ uint32_t messages_begin;
+ uint32_t messages_end;
} vhffsfssync_conn;
-
-typedef struct {
- char *data_buffer;
- ssize_t data_len;
- ssize_t data_cur;
-} vhffsfssync_net_message;
-
// network protos
int vhffsfssync_net_send_data(vhffsfssync_conn *conn, char *data, ssize_t len);
void vhffsfssync_net_destroy_message(vhffsfssync_conn *conn, vhffsfssync_net_message *msg);
@@ -89,20 +89,22 @@
msg->data_buffer = data;
msg->data_len = len;
msg->data_cur = 0;
- conn->messages = g_list_append(conn->messages, msg);
+ if( !(conn->messages_end & 0x03FF) )
+ conn->messages = realloc( conn->messages, (((conn->messages_end >>10) +1) <<10) * sizeof(vhffsfssync_net_message*) );
+ conn->messages[conn->messages_end] = msg;
+ conn->messages_end++;
+
return 0;
}
void vhffsfssync_net_destroy_message(vhffsfssync_conn *conn, vhffsfssync_net_message *msg) {
- conn->messages = g_list_remove(conn->messages, msg);
free(msg->data_buffer);
free(msg);
}
int vhffsfssync_net_send(vhffsfssync_conn *conn) {
- GList *msgs;
gboolean full = FALSE;
if(!conn || conn->fd < 0) return -1;
@@ -110,8 +112,8 @@
printf("--------------------------------------------------\n");
printf("conn: %d, to: %s\n", conn->fd, inet_ntoa(conn->sockaddr.sin_addr));
#endif
- while(!full && (msgs = g_list_first(conn->messages)) ) {
- vhffsfssync_net_message *msg = msgs->data;
+ while(!full && conn->messages) {
+ vhffsfssync_net_message *msg = conn->messages[conn->messages_begin];
ssize_t written;
ssize_t lentowrite;
@@ -147,6 +149,25 @@
/* buffer is now empty */
else {
vhffsfssync_net_destroy_message(conn, msg);
+
+ conn->messages_begin++;
+ if(conn->messages_begin == conn->messages_end) {
+ conn->messages_begin = 0;
+ conn->messages_end = 0;
+ free(conn->messages);
+ conn->messages = NULL;
+ break;
+ }
+ if(conn->messages_begin == 0x0400) {
+ void *cur, *end;
+ conn->messages_begin = 0;
+ conn->messages_end -= 0x0400;
+ cur = conn->messages;
+ end = conn->messages + conn->messages_end;
+ for( ; cur < end ; cur += 0x0400*sizeof(void*) )
+ memcpy(cur, cur + 0x0400*sizeof(void*), 0x0400*sizeof(void*) );
+ conn->messages = realloc( conn->messages, (((conn->messages_end >>10) +1) <<10) * sizeof(vhffsfssync_net_message*) );
+ }
}
}
}
@@ -547,6 +568,8 @@
conn->chunk_stilltoread = 0;
conn->chunk_file = NULL;
conn->messages = NULL;
+ conn->messages_begin = 0;
+ conn->messages_end = 0;
/* -- main loop -- */
while(1) {
@@ -561,20 +584,19 @@
conn->buf_cur = conn->buf;
conn->chunk_stilltoread = 0;
- if(conn->chunk_file) {
- fclose(conn->chunk_file);
- }
+ if(conn->chunk_file) fclose(conn->chunk_file);
conn->chunk_file = NULL;
if(conn->messages) {
- GList *msg;
- while( (msg = g_list_first(conn->messages)) ) {
- vhffsfssync_net_destroy_message(conn, (vhffsfssync_net_message*)msg->data);
- }
+ uint32_t i;
+ for(i = conn->messages_begin ; i < conn->messages_end ; i++)
+ vhffsfssync_net_destroy_message(conn, conn->messages[i]);
+ free(conn->messages);
}
conn->messages = NULL;
+ conn->messages_begin = 0;
+ conn->messages_end = 0;
-
/* connect */
inet_aton(host, &conn->sockaddr.sin_addr);
conn->sockaddr.sin_family = AF_INET;