diff --git a/src/client/sock.c b/src/client/sock.c
index b3be6157996fe7002661b783db2c055d7a382e45..18ab6a586a1c9f44018629533e4752ecf2ccfa73 100644 (file)
--- a/src/client/sock.c
+++ b/src/client/sock.c
} /* sdb_client_destroy */
int
-sdb_client_connect(sdb_client_t *client)
+sdb_client_connect(sdb_client_t *client, const char *username)
{
+ sdb_strbuf_t *buf;
+ ssize_t status;
+ uint32_t rstatus;
+
if ((! client) || (! client->address))
return -1;
if (client->fd < 0)
return -1;
+
+ /* XXX */
+ if (! username)
+ username = "";
+
+ status = sdb_client_send(client, CONNECTION_STARTUP,
+ (uint32_t)strlen(username), username);
+ if (status < 0) {
+ sdb_client_close(client);
+ return (int)status;
+ }
+
+ buf = sdb_strbuf_create(64);
+ rstatus = 0;
+ status = sdb_client_recv(client, &rstatus, buf);
+ if (status < 0) {
+ sdb_client_close(client);
+ sdb_strbuf_destroy(buf);
+ return (int)status;
+ }
+
+ if (rstatus != CONNECTION_OK) {
+ sdb_client_close(client);
+ sdb_strbuf_destroy(buf);
+ return -((int)rstatus);
+ }
return 0;
} /* sdb_client_connect */