*** empty log message ***
[mmondor.git] / tests / bktr_httpd / client.c
CommitLineData
e583c3d8 1/* $Id: client.c,v 1.4 2008/01/20 18:11:37 mmondor Exp $ */
ce436d0b
MM
2
3/*
4 * Copyright (c) 2008, Matthew Mondor
5 * ALL RIGHTS RESERVED.
6 */
7
8
9#include <stdlib.h>
e583c3d8 10#include <unistd.h>
ce436d0b 11
dacf6158 12#include "net.h"
ce436d0b 13#include "client.h"
e583c3d8 14#include "sendq.h"
ce436d0b
MM
15
16
17static pool_t client_pool;
18
fa6ec601
MM
19list_t client_list;
20
ce436d0b
MM
21
22bool
23client_init(void)
24{
25
26 if (!pool_init(&client_pool, "client_pool", malloc, free, NULL, NULL,
27 sizeof(client_t), 65536 / sizeof(client_t), 1, 0))
28 return false;
29
30 return true;
31}
32
33client_t *
e583c3d8 34client_new(netaddr_t *naddr, int fd)
ce436d0b
MM
35{
36 client_t *c;
37
38 if ((c = (client_t *)pool_alloc(&client_pool, false)) != NULL) {
39 DLIST_INIT(&c->sendq);
dacf6158 40 c->netaddr = naddr;
e583c3d8
MM
41 c->fd = fd;
42 c->first = true;
43 c->skip = c->skipcnt = 0;
44 c->received = 0;
ce436d0b 45 }
fa6ec601 46 DLIST_APPEND(&client_list, (node_t *)c);
ce436d0b
MM
47
48 return c;
49}
50
51void
52client_destroy(client_t *c)
53{
54
e583c3d8 55 (void) close(c->fd);
fa6ec601 56 DLIST_UNLINK(&client_list, (node_t *)c);
e583c3d8 57 sendq_purge(&c->sendq, true);
dacf6158 58 netaddr_destroy(c->netaddr);
ce436d0b
MM
59 (void) pool_free((pnode_t *)c);
60}