+ pthread_mutex_unlock (&cache_lock);
+
+ if (values_num < 1)
+ {
+ /* journal replay mode */
+ if (sock == NULL) return RESP_ERR;
+
+ /* if we had only one update attempt, then return the full
+ error message... try to get the most information out
+ of the limited error space allowed by the protocol
+ */
+ if (bad_timestamps == 1)
+ return send_response(sock, RESP_ERR, "%s", sock->wbuf);
+ else
+ return send_response(sock, RESP_ERR,
+ "No values updated (%d bad timestamps).\n",
+ bad_timestamps);
+ }
+ else
+ return send_response(sock, RESP_OK,
+ "errors, enqueued %i value(s).\n", values_num);
+
+ /* NOTREACHED */
+ assert(1==0);
+
+} /* }}} int handle_request_update */
+
+/* we came across a "WROTE" entry during journal replay.
+ * throw away any values that we have accumulated for this file
+ */
+static int handle_request_wrote (const char *buffer, time_t now) /* {{{ */
+{
+ int i;
+ cache_item_t *ci;
+ const char *file = buffer;
+
+ pthread_mutex_lock(&cache_lock);
+
+ ci = g_tree_lookup(cache_tree, file);
+ if (ci == NULL)
+ {
+ pthread_mutex_unlock(&cache_lock);
+ return (0);
+ }
+
+ if (ci->values)
+ {
+ for (i=0; i < ci->values_num; i++)
+ free(ci->values[i]);
+
+ free(ci->values);
+ }
+
+ wipe_ci_values(ci, now);
+ remove_from_queue(ci);
+
+ pthread_mutex_unlock(&cache_lock);
+ return (0);
+} /* }}} int handle_request_wrote */
+
+/* start "BATCH" processing */
+static int batch_start (listen_socket_t *sock) /* {{{ */
+{
+ int status;
+ if (sock->batch_start)
+ return send_response(sock, RESP_ERR, "Already in BATCH\n");
+
+ status = send_response(sock, RESP_OK,
+ "Go ahead. End with dot '.' on its own line.\n");
+ sock->batch_start = time(NULL);
+ sock->batch_cmd = 0;
+
+ return status;
+} /* }}} static int batch_start */
+
+/* finish "BATCH" processing and return results to the client */
+static int batch_done (listen_socket_t *sock) /* {{{ */
+{
+ assert(sock->batch_start);
+ sock->batch_start = 0;
+ sock->batch_cmd = 0;
+ return send_response(sock, RESP_OK, "errors\n");
+} /* }}} static int batch_done */
+
+/* if sock==NULL, we are in journal replay mode */
+static int handle_request (listen_socket_t *sock, /* {{{ */
+ time_t now,
+ char *buffer, size_t buffer_size)
+{
+ char *buffer_ptr;
+ char *command;
+ int status;
+
+ assert (buffer[buffer_size - 1] == '\0');
+
+ buffer_ptr = buffer;
+ command = NULL;
+ status = buffer_get_field (&buffer_ptr, &buffer_size, &command);
+ if (status != 0)
+ {
+ RRDD_LOG (LOG_INFO, "handle_request: Unable parse command.");
+ return (-1);
+ }
+
+ if (sock != NULL && sock->batch_start)
+ sock->batch_cmd++;