X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fttt-client.h;h=452b36fa0d73ec492a506f2a2fcac5b071e96b27;hp=b067674fdbc7b2fb7e1696d28462747b38e1fbe5;hb=15672ac8305a1c5ba0d9bf6edabb0a194c30628e;hpb=5d56d3cd8b4685e905ed604277ac9cb32c876127 diff --git a/src/ttt-client.h b/src/ttt-client.h index b067674..452b36f 100644 --- a/src/ttt-client.h +++ b/src/ttt-client.h @@ -26,10 +26,28 @@ #ifndef _TTT_CLIENT_H_ #define _TTT_CLIENT_H_ -typedef struct _ttt_client ttt_client_t; +#define TTT_CLIENT_BUF_SIZE 1024 + +typedef struct _ttt_client { + pthread_t thread; + + ttt_server_t *server; + int socket; + + int id; + + char buf[TTT_CLIENT_BUF_SIZE]; + char *buf_head; + char *buf_tail; + + char *request; + int request_size; + int request_len; +} ttt_client_t; + /* Create a new ttt_client_t for the given server and given a - * connected socket. + * connected socket, and assign it the given id. * * Returns: A new ttt_client_t. Call ttt_client_destroy when finished * with it. @@ -38,13 +56,26 @@ typedef struct _ttt_client ttt_client_t; * will not return. */ ttt_client_t * -ttt_client_create (ttt_server_t *server, int socket); +ttt_client_create (ttt_server_t *server, int socket, int id); +/* Destroy a client. */ void ttt_client_destroy (ttt_client_t *client); -/* Loop forever handling client requests. Never returns. */ +/* Perform a blocking read until a newline is encountered. + * + * Returns: A pointer to the string read, or NULL if EOF occurs. This + * string points to data internal to the client and can be overwritten + * by subsequent calls to this function. + * + * Errors: If any error (other than reading EOF) occurs, this function + * will not return. + */ +char * +ttt_client_read_line (ttt_client_t *client); + +/* Send a message to a client. */ void -ttt_client_handle_requests (ttt_client_t *client); +ttt_client_send (ttt_client_t *client, const char *message); #endif /* _TTT_CLIENT_H_ */