index b48de2c893ccbc9d9c65de335fecbb66c3421733..69c71edbd3e6f7ac9e5876841d9237f738267ab5 100644 (file)
#include "core/object.h"
#include "core/plugin.h"
#include "frontend/connection-private.h"
+#include "frontend/parser.h"
#include "utils/error.h"
#include "utils/strbuf.h"
#include "utils/proto.h"
sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection on fd=%i",
conn->fd);
- close(conn->fd);
+ if (conn->fd >= 0)
+ close(conn->fd);
conn->fd = -1;
sdb_strbuf_destroy(conn->buf);
node = SDB_CONN_NODE(sdb_llist_get(parsetree, 0));
}
- if (node)
+ if (node) {
status = sdb_fe_exec(conn, node);
+ sdb_object_deref(SDB_OBJ(node));
+ }
sdb_llist_destroy(parsetree);
break;
}
+ case CONNECTION_FETCH:
+ status = sdb_fe_fetch(conn, sdb_strbuf_string(conn->buf));
+ break;
case CONNECTION_LIST:
status = sdb_fe_list(conn);
break;
+ case CONNECTION_LOOKUP:
+ {
+ sdb_store_matcher_t *m;
+
+ m = sdb_fe_parse_matcher(sdb_strbuf_string(conn->buf),
+ (int)conn->cmd_len);
+ if (! m) {
+ sdb_log(SDB_LOG_ERR, "frontend: Failed to parse expression '%s'",
+ sdb_strbuf_string(conn->buf));
+ status = -1;
+ break;
+ }
+
+ status = sdb_fe_lookup(conn, m);
+ sdb_object_deref(SDB_OBJ(m));
+ break;
+ }
default:
{
{
ssize_t n = 0;
+ if ((! conn) || (conn->fd < 0))
+ return -1;
+
while (42) {
ssize_t status;
if (status < 0) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
break;
+
+ close(conn->fd);
+ conn->fd = -1;
return (int)status;
}
else if (! status) /* EOF */
if (status < 0) {
char errbuf[1024];
+ /* tell other code that there was a problem and, more importantly,
+ * make sure we don't try to send further logs to the connection */
+ close(conn->fd);
+ conn->fd = -1;
+
sdb_log(SDB_LOG_ERR, "frontend: Failed to send msg "
"(code: %u, len: %u) to client: %s", code, msg_len,
sdb_strerror(errno, errbuf, sizeof(errbuf)));