X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fconnection.c;h=ed1eb2c8565058f562922f3d0b11071d46287ccb;hb=af24300b64d721ec7e3be3edee1477d83b135f8b;hp=66ccfd4c2fb727009063ddbb85288d3e2caa0310;hpb=9610de881cfcd9bd15e064230714ae15cf621885;p=sysdb.git diff --git a/src/frontend/connection.c b/src/frontend/connection.c index 66ccfd4..ed1eb2c 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -36,6 +36,7 @@ #include "utils/error.h" #include "utils/strbuf.h" #include "utils/proto.h" +#include "utils/os.h" #include #include @@ -200,9 +201,7 @@ connection_destroy(sdb_object_t *obj) } 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); @@ -326,6 +325,8 @@ command_handle(sdb_conn_t *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); @@ -357,9 +358,9 @@ command_init(sdb_conn_t *conn) /* 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)) @@ -404,8 +405,7 @@ connection_read(sdb_conn_t *conn) if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break; - close(conn->fd); - conn->fd = -1; + sdb_connection_close(conn); return (int)status; } else if (! status) /* EOF */ @@ -462,12 +462,10 @@ sdb_connection_close(sdb_conn_t *conn) if (conn->fd >= 0) close(conn->fd); conn->fd = -1; - - sdb_object_deref(SDB_OBJ(conn)); } /* sdb_connection_close */ ssize_t -sdb_connection_read(sdb_conn_t *conn) +sdb_connection_handle(sdb_conn_t *conn) { ssize_t n = 0; @@ -498,7 +496,7 @@ sdb_connection_read(sdb_conn_t *conn) sdb_conn_set_ctx(NULL); return n; -} /* sdb_connection_read */ +} /* sdb_connection_handle */ ssize_t sdb_connection_send(sdb_conn_t *conn, uint32_t code, @@ -512,14 +510,13 @@ sdb_connection_send(sdb_conn_t *conn, uint32_t code, 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 */ - close(conn->fd); - conn->fd = -1; + sdb_connection_close(conn); conn->ready = 0; sdb_log(SDB_LOG_ERR, "frontend: Failed to send msg "