+// Cleanup channel
+static void http_destroy(IOCHAN i)
+{
+ struct http_channel *s = iochan_getdata(i);
+
+ if (s->proxy)
+ {
+ if (s->proxy->iochan)
+ {
+ close(iochan_getfd(s->proxy->iochan));
+ iochan_destroy(s->proxy->iochan);
+ }
+ http_buf_destroy_queue(s->proxy->oqueue);
+ xfree(s->proxy);
+ }
+ s->next = http_channel_freelist;
+ http_channel_freelist = s;
+ close(iochan_getfd(i));
+ iochan_destroy(i);
+}
+
+static struct http_channel *http_create(void)
+{
+ struct http_channel *r = http_channel_freelist;
+
+ if (r)
+ {
+ http_channel_freelist = r->next;
+ nmem_reset(r->nmem);
+ wrbuf_rewind(r->wrbuf);
+ }
+ else
+ {
+ r = xmalloc(sizeof(struct http_channel));
+ r->nmem = nmem_create();
+ r->wrbuf = wrbuf_alloc();
+ }
+ r->proxy = 0;
+ r->iochan = 0;
+ r->iqueue = r->oqueue = 0;
+ r->state = Http_Idle;
+ r->request = 0;
+ r->response = 0;
+ return r;
+}
+
+