[tracker/tracker-store-ipc] Sending back the ERR or OK to the client
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-store-ipc] Sending back the ERR or OK to the client
- Date: Fri, 29 May 2009 05:22:50 -0400 (EDT)
commit 78a317443dc6d0388910c35a9e39c4a14234b81d
Author: Philip Van Hoof <philip codeminded be>
Date: Fri May 29 11:21:35 2009 +0200
Sending back the ERR or OK to the client
---
src/tracker-store/tracker-socket-listener.c | 77 +++++++++++++++++++++++++--
tests/estress/socket_stress_test.c | 4 +-
2 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/src/tracker-store/tracker-socket-listener.c b/src/tracker-store/tracker-socket-listener.c
index a580573..6aac946 100644
--- a/src/tracker-store/tracker-socket-listener.c
+++ b/src/tracker-store/tracker-socket-listener.c
@@ -39,26 +39,76 @@
static int sockfd = -1;
static gchar standard_buffer[4028];
+static GArray* just_died = NULL;
+
+typedef struct {
+ gchar *key;
+ gint clientfd;
+} UpdateFinInfo;
+
+static void
+update_info_free (UpdateFinInfo *info)
+{
+ g_free (info->key);
+ g_slice_free (UpdateFinInfo, info);
+}
+
+static void
+on_commit_fin (gpointer user_data)
+{
+ g_array_free (just_died, TRUE);
+ just_died = NULL;
+}
+
+static void
+on_update_fin (GError *error,
+ gpointer user_data)
+{
+ UpdateFinInfo *info = user_data;
+ gchar *message;
+ guint i;
+
+ if (just_died) {
+ for (i = 0; i < just_died->len; i++) {
+ if (info->clientfd == g_array_index (just_died, int, i)) {
+ return;
+ }
+ }
+ }
+
+ if (error) {
+ message = g_strdup_printf ("ER:%s:%s", info->key, error->message);
+ } else {
+ message = g_strdup_printf ("OK:%s", info->key);
+ }
+
+ send (info->clientfd, message, strlen (message), 0);
+}
static gboolean
data_to_handle_received (GIOChannel *source,
GIOCondition cond,
gpointer data)
{
+ gint clientfd = (int) data;
+
if (cond & G_IO_IN) {
- gchar command[20];
+ gchar command[33];
gsize len;
- gint clientfd;
- clientfd = (int) data;
len = recv (clientfd, command, sizeof (command), 0);
- if (len == sizeof (command) && command[7] == '{' && command[18] == '}') {
+ if (len == sizeof (command) && command[7] == '{' && command[18] == '}' &&
+ command[20] == '{' && command[31] == '}') {
+
gchar *ptr = command + 8;
+ const gchar *key = command + 21;
guint data_length;
gchar *free_data = NULL, *query_data;
command[18] = '\0';
+ command[31] = '\0';
+
data_length = atol (ptr);
if (data_length > sizeof (standard_buffer)) {
@@ -73,9 +123,17 @@ data_to_handle_received (GIOChannel *source,
if (len == data_length) {
if (strstr (command, "UPDATE")) {
+ UpdateFinInfo *info = g_slice_new (UpdateFinInfo);
+
+ info->key = g_strdup (key);
+ info->clientfd = clientfd;
+
/* g_debug ("QUEUED: %s\n", query_data); */
+
tracker_store_queue_sparql_update (query_data,
- NULL, NULL, NULL);
+ on_update_fin,
+ info,
+ (GDestroyNotify) update_info_free);
} else {
goto failed;
@@ -93,6 +151,13 @@ data_to_handle_received (GIOChannel *source,
}
if (cond & (G_IO_HUP | G_IO_ERR)) {
+ if (!just_died) {
+ just_died = g_array_new (FALSE, TRUE, sizeof (int));
+ }
+
+ g_array_append_val (just_died, clientfd);
+ tracker_store_queue_commit (on_commit_fin, NULL, NULL);
+
goto failed;
}
@@ -166,6 +231,8 @@ tracker_socket_listener_init (void)
listen (sockfd, 1);
io = g_io_channel_unix_new (sockfd);
+ signal(SIGPIPE, SIG_IGN);
+
g_io_add_watch (io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
server_cb, NULL);
diff --git a/tests/estress/socket_stress_test.c b/tests/estress/socket_stress_test.c
index c805fbd..1da9e0d 100755
--- a/tests/estress/socket_stress_test.c
+++ b/tests/estress/socket_stress_test.c
@@ -43,12 +43,12 @@ int main(void)
printf("Connected.\n");
- str = "UPDATE {0000000032}\nINSERT { <test> a nfo:Document }";
+ str = "UPDATE {0000000032} {0000000032}\nINSERT { <test> a nfo:Document }";
timer = g_timer_new ();
g_timer_start (timer);
- for (i = 0; i < 10000; i++) {
+ for (i = 0; i < 100000; i++) {
if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]