]> git.cworth.org Git - ttt/blobdiff - src/ttt-client.h
2005-11-24 Carl Worth <cworth@cworth.org>
[ttt] / src / ttt-client.h
index 452b36fa0d73ec492a506f2a2fcac5b071e96b27..06af64b079a1a113287a4f1038226632724b1c00 100644 (file)
 
 #include "ttt.h"
 
-#include "ttt-server.h"
-
 #ifndef _TTT_CLIENT_H_
 #define _TTT_CLIENT_H_
 
 #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 client and start a new thread to handle all requests
+ * from the client. */
+void
+ttt_client_new (void *closure, int client_socket);
 
-/* Create a new ttt_client_t for the given server and given a
- * connected socket, and assign it the given id.
+/* Send a message to a client.
  *
- * Returns: A new ttt_client_t. Call ttt_client_destroy when finished
- * with it.
+ * Locking: The client mutex will be acquired and held throughout the
+ * execution of this function.
  *
- * Errors: If any error occurs, (such as out-of-memory), this function
- * will not return.
+ * Errors: If an IO error occurs, this function will not return.
  */
-ttt_client_t *
-ttt_client_create (ttt_server_t *server, int socket, int id);
-
-/* Destroy a client. */
 void
-ttt_client_destroy (ttt_client_t *client);
+ttt_client_send (ttt_client_t *client, const char *message);
 
-/* 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);
+/* Get a client's name. */
+const char*
+ttt_client_get_name (ttt_client_t *client);
 
-/* Send a message to a client. */
+/* Set a client's name. */
 void
-ttt_client_send (ttt_client_t *client, const char *message);
+ttt_client_set_name (ttt_client_t *client, const char *name);
 
 #endif /* _TTT_CLIENT_H_ */