Code

connection: Use sdb_connection_close to close a connection.
[sysdb.git] / src / frontend / connection.c
index 58a2cb4d3e3d06d510927b57b414f37bc3af425c..55843fd049d9e2569c24b8d42c6d20776039929d 100644 (file)
@@ -201,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);
@@ -358,9 +356,8 @@ 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(conn->buf, &conn->cmd, &conn->cmd_len))
+               return -1;
        sdb_strbuf_skip(conn->buf, 0, 2 * sizeof(uint32_t));
 
        if ((! conn->ready) && (conn->cmd != SDB_CONNECTION_STARTUP))
@@ -405,8 +402,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 */
@@ -517,8 +513,7 @@ sdb_connection_send(sdb_conn_t *conn, uint32_t code,
 
                /* 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 "