From 3a2b73b3c6dac91176b2e086a621e31dcca74e1b Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 16 Jan 2015 23:46:25 +0100 Subject: [PATCH] client: Use sdb_client_rpc in sdb_client_connect. --- src/client/sock.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/client/sock.c b/src/client/sock.c index 6a1e49f..cb506a5 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -224,30 +224,22 @@ sdb_client_connect(sdb_client_t *client, const char *username) if (! username) username = ""; - status = sdb_client_send(client, SDB_CONNECTION_STARTUP, - (uint32_t)strlen(username), username); - if (status < 0) { - char errbuf[1024]; - sdb_client_close(client); - sdb_log(SDB_LOG_ERR, "Failed to send STARTUP message to server: %s", - sdb_strerror(errno, errbuf, sizeof(errbuf))); - return (int)status; - } - buf = sdb_strbuf_create(64); rstatus = 0; - status = sdb_client_recv(client, &rstatus, buf); - if ((status > 0) && (rstatus == SDB_CONNECTION_OK)) { + status = sdb_client_rpc(client, SDB_CONNECTION_STARTUP, + (uint32_t)strlen(username), username, &rstatus, buf); + if ((status >= 0) && (rstatus == SDB_CONNECTION_OK)) { sdb_strbuf_destroy(buf); return 0; } if (status < 0) { - char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "Failed to receive server response: %s", - sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_log(SDB_LOG_ERR, "%s", sdb_strbuf_string(buf)); + sdb_client_close(client); + sdb_strbuf_destroy(buf); + return (int)status; } - else if (client->eof) + if (client->eof) sdb_log(SDB_LOG_ERR, "Encountered end-of-file while waiting " "for server response"); -- 2.30.2