-/* ttt.c - client-server tic-tac-toe game
+/* ttt-client.c - client handling code for tic-tac-toe game server
*
* Copyright © 2005 Carl Worth
*
* Author: Carl Worth <cworth@cworth.org>
*/
-#include "ttt.h"
+#include "ttt-client.h"
-int
-main (int argc, char **argv)
+struct _ttt_client {
+ ttt_server_t *server;
+ int socket;
+};
+
+ttt_client_t *
+ttt_client_create (ttt_server_t *server, int socket)
{
- ttt_args_t args;
- int args_first;
+ ttt_client_t *client;
+
+ client = xmalloc (sizeof (ttt_client_t));
+
+ client->server = server;
+ client->socket = socket;
- ttt_args_parse (&args, argc, argv, &args_first);
+ return client;
+}
- /* XXX: insert code here */
+void
+ttt_client_destroy (ttt_client_t *client)
+{
+ close (client->socket);
- return 0;
+ free (client);
}
+
+void
+ttt_client_handle_requests (ttt_client_t *client)
+{
+#define BUF_SIZE 1024
+
+ while (1) {
+ char buf[BUF_SIZE];
+ int cnt;
+ cnt = read (client->socket, buf, BUF_SIZE);
+ if (cnt == 0)
+ break;
+ write (0, buf, cnt);
+ write (client->socket, buf, cnt);
+ }
+}
+
+