X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fttt-client.c;fp=src%2Fttt-client.c;h=80fca846e13ee46e4fae37b87ee966901a91de9a;hp=d6b6fe7b4e474d9c7ce4f7962bdbe1fdaab876f4;hb=5d56d3cd8b4685e905ed604277ac9cb32c876127;hpb=ded32923a25488449be27687013845d7fa0e9e5e diff --git a/src/ttt-client.c b/src/ttt-client.c index d6b6fe7..80fca84 100644 --- a/src/ttt-client.c +++ b/src/ttt-client.c @@ -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 * @@ -19,16 +19,48 @@ * Author: Carl Worth */ -#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; + ttt_client_t *client; + + client = xmalloc (sizeof (ttt_client_t)); + + client->server = server; + client->socket = socket; - ttt_args_parse (&args, argc, argv); + 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); + } +} + +