]> git.cworth.org Git - ttt/blobdiff - src/ttt-client.c
2005-11-11 Carl Worth <cworth@cworth.org>
[ttt] / src / ttt-client.c
index b42db7a95064811b95fff78b4f0070236b4fe69c..80fca846e13ee46e4fae37b87ee966901a91de9a 100644 (file)
@@ -1,4 +1,4 @@
-/* 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);
+    }
+}
+
+