+
+static ttt_status_t
+ttt_client_read_into_request_until (ttt_client_t *client, char delimeter)
+{
+ ttt_bool_t found_delimeter = FALSE;
+ int bytes_read;
+ char *s;
+
+ client->request_len = 0;
+
+ while (1) {
+
+ if (client->buf_tail >= client->buf_head) {
+ bytes_read = xread (client->socket,
+ client->buf,
+ TTT_CLIENT_BUF_SIZE);
+ if (bytes_read == 0)
+ return TTT_STATUS_EOF;
+ client->buf_head = client->buf;
+ client->buf_tail = client->buf_head + bytes_read;
+ }
+
+ for (s = client->buf_head; s < client->buf_tail; s++) {
+ if (*s == delimeter) {
+ found_delimeter = TRUE;
+ s++;
+ break;
+ }
+ }
+
+ _append_to_request (client,
+ client->buf_head,
+ s - client->buf_head);
+ client->buf_head = s;
+
+ if (found_delimeter)
+ return TTT_STATUS_SUCCESS;
+ }
+}
+
+char *
+ttt_client_read_line (ttt_client_t *client)
+{
+ ttt_status_t status;
+ static const char null_terminator = '\0';
+
+ status = ttt_client_read_into_request_until (client, '\n');
+ if (status) {
+ assert (status == TTT_STATUS_EOF);
+ return NULL;
+ }
+
+ _append_to_request (client, &null_terminator, 1);
+
+ return client->request;
+}
+
+void
+ttt_client_send (ttt_client_t *client, const char *message)
+{
+ ttt_socket_write (client->socket, message, strlen (message));
+}
+
+