index cf610ac45a06951a82c00644a943ef43d5da8ced..ed1eb2c8565058f562922f3d0b11071d46287ccb 100644 (file)
#include "utils/error.h"
#include "utils/strbuf.h"
#include "utils/proto.h"
#include "utils/error.h"
#include "utils/strbuf.h"
#include "utils/proto.h"
+#include "utils/os.h"
#include <assert.h>
#include <errno.h>
#include <assert.h>
#include <errno.h>
}
sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection %s", obj->name);
}
sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection %s", obj->name);
- if (conn->fd >= 0)
- close(conn->fd);
- conn->fd = -1;
+ sdb_connection_close(conn);
if (conn->username)
free(conn->username);
if (conn->username)
free(conn->username);
status = sdb_fe_list(conn);
else if (conn->cmd == SDB_CONNECTION_LOOKUP)
status = sdb_fe_lookup(conn);
status = sdb_fe_list(conn);
else if (conn->cmd == SDB_CONNECTION_LOOKUP)
status = sdb_fe_lookup(conn);
+ else if (conn->cmd == SDB_CONNECTION_STORE)
+ status = sdb_fe_store(conn);
else {
sdb_log(SDB_LOG_WARNING, "frontend: Ignoring invalid command %#x",
conn->cmd);
else {
sdb_log(SDB_LOG_WARNING, "frontend: Ignoring invalid command %#x",
conn->cmd);
/* reset */
sdb_strbuf_clear(conn->errbuf);
/* reset */
sdb_strbuf_clear(conn->errbuf);
- conn->cmd = sdb_proto_get_int(conn->buf, 0);
- conn->cmd_len = sdb_proto_get_int(conn->buf, sizeof(uint32_t));
-
+ if (sdb_proto_unmarshal_header(SDB_STRBUF_STR(conn->buf),
+ &conn->cmd, &conn->cmd_len) < 0)
+ return -1;
sdb_strbuf_skip(conn->buf, 0, 2 * sizeof(uint32_t));
if ((! conn->ready) && (conn->cmd != SDB_CONNECTION_STARTUP))
sdb_strbuf_skip(conn->buf, 0, 2 * sizeof(uint32_t));
if ((! conn->ready) && (conn->cmd != SDB_CONNECTION_STARTUP))
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
break;
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
break;
- close(conn->fd);
- conn->fd = -1;
+ sdb_connection_close(conn);
return (int)status;
}
else if (! status) /* EOF */
return (int)status;
}
else if (! status) /* EOF */
if (sdb_proto_marshal(buf, sizeof(buf), code, msg_len, msg) < 0)
return -1;
if (sdb_proto_marshal(buf, sizeof(buf), code, msg_len, msg) < 0)
return -1;
- status = sdb_proto_send(conn->fd, sizeof(buf), buf);
+ status = sdb_write(conn->fd, sizeof(buf), buf);
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 */
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_connection_close(conn);
conn->ready = 0;
sdb_log(SDB_LOG_ERR, "frontend: Failed to send msg "
conn->ready = 0;
sdb_log(SDB_LOG_ERR, "frontend: Failed to send msg "