index 12812c7132b20e35da6954757ddbcb5f6f2e7a7d..6b785392a1255311d5fae116a1bfb334186534db 100644 (file)
"(%zu byte%s left in buffer)", len, len == 1 ? "" : "s");
}
- sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection on fd=%i",
- conn->fd);
- close(conn->fd);
+ sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection %s", obj->name);
+ if (conn->fd >= 0)
+ close(conn->fd);
conn->fd = -1;
+ if (conn->username)
+ free(conn->username);
+ conn->username = NULL;
+
sdb_strbuf_destroy(conn->buf);
conn->buf = NULL;
sdb_strbuf_destroy(conn->errbuf);
static void
sdb_conn_set_ctx(sdb_conn_t *conn)
{
+ sdb_conn_t *old;
+
sdb_conn_ctx_init();
+
+ old = pthread_getspecific(conn_ctx_key);
+ if (old)
+ sdb_object_deref(SDB_OBJ(old));
if (conn)
sdb_object_ref(SDB_OBJ(conn));
pthread_setspecific(conn_ctx_key, conn);
const char *errmsg = "Authentication required";
sdb_connection_send(conn, CONNECTION_ERROR,
(uint32_t)strlen(errmsg), errmsg);
+
+ /* remove the command from the buffer */
+ if (conn->cmd_len)
+ sdb_strbuf_skip(conn->buf, 0, conn->cmd_len);
return -1;
}
{
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 */
void
sdb_connection_close(sdb_conn_t *conn)
{
+ if (! conn)
+ return;
+
+ /* close the connection even if someone else still references it */
+ if (conn->fd >= 0)
+ close(conn->fd);
+ conn->fd = -1;
+
sdb_object_deref(SDB_OBJ(conn));
} /* sdb_connection_close */
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)));