From f046d1cdc1010ecfe1b3928d5984349fd48dc08d Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 19 Dec 2006 13:19:32 +0000 Subject: [PATCH] add iob_bytesleft don't leak memory in test/httpd.c --- CHANGES | 2 ++ io/iob_bytesleft.3 | 15 +++++++++++++++ io/iob_bytesleft.c | 5 +++++ iob.h | 1 + test/httpd.c | 16 +++++++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 io/iob_bytesleft.3 create mode 100644 io/iob_bytesleft.c diff --git a/CHANGES b/CHANGES index f3f6abc..03608a1 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,8 @@ add asm versions of imult64 and umult64 for x86_64 (22 cycles -> 12 cycles on my Athlon 64) use size_t and ssize_t instead of unsigned long et al + add iob_bytesleft + don't leak memory in test/httpd 0.24: fix scan_to_sa (Tim Lorenz) diff --git a/io/iob_bytesleft.3 b/io/iob_bytesleft.3 new file mode 100644 index 0000000..fe596f6 --- /dev/null +++ b/io/iob_bytesleft.3 @@ -0,0 +1,15 @@ +.TH iob_bytesleft 3 +.SH NAME +iob_bytesleft \- how many bytes are still to be sent? +.SH SYNTAX +.B #include + +uint64 \fBiob_bytesleft\fP(const io_batch* b); +.SH DESCRIPTION +iob_bytesleft returns the number of bytes that still need to be sent in +this IO batch. If you just want to see whether you need to call +iob_send again, there is no advantage in this function to calling +iob_send directly and looking whether it returned 0. + +.SH "SEE ALSO" +iob_send(3) diff --git a/io/iob_bytesleft.c b/io/iob_bytesleft.c new file mode 100644 index 0000000..40393cf --- /dev/null +++ b/io/iob_bytesleft.c @@ -0,0 +1,5 @@ +#include "iob.h" + +uint64 iob_bytesleft(const io_batch* b) { + return b->bytesleft; +} diff --git a/iob.h b/iob.h index c791ca4..4cdbe1d 100644 --- a/iob.h +++ b/iob.h @@ -33,5 +33,6 @@ int64 iob_write(int64 s,io_batch* b,io_write_callback cb); void iob_reset(io_batch* b); void iob_free(io_batch* b); void iob_prefetch(io_batch* b,uint64 bytes); +uint64 iob_bytesleft(const io_batch* b); #endif diff --git a/test/httpd.c b/test/httpd.c index f6f7aa6..6ad389d 100644 --- a/test/httpd.c +++ b/test/httpd.c @@ -182,6 +182,16 @@ e404: io_wantwrite(s); } +void cleanup(int64 socket) { + struct http_data*x=io_getcookie(socket); + if (x) { + array_reset(&x->r); + iob_free(&x->iob); + free(x->hdrbuf); + free(x); + } +} + int main() { int s=socket_tcp6b(); uint32 scope_id; @@ -242,6 +252,7 @@ int main() { buffer_puts(buffer_2,"): "); buffer_puterror(buffer_2); buffer_putnlflush(buffer_2); + cleanup(i); io_close(i); } else if (l==0) { if (h) { @@ -252,6 +263,7 @@ int main() { buffer_puts(buffer_2,"eof on fd #"); buffer_putulong(buffer_2,i); buffer_putnlflush(buffer_2); + cleanup(i); io_close(i); } else if (l>0) { array_catb(&h->r,buf,l); @@ -280,8 +292,10 @@ emerge: if (h->keepalive) { io_dontwantwrite(i); io_wantread(i); - } else + } else { + cleanup(i); io_close(i); + } } } }