add iob_bytesleft

don't leak memory in test/httpd.c
master
leitner 18 years ago
parent e443e06b28
commit f046d1cdc1

@ -21,6 +21,8 @@
add asm versions of imult64 and umult64 for x86_64 add asm versions of imult64 and umult64 for x86_64
(22 cycles -> 12 cycles on my Athlon 64) (22 cycles -> 12 cycles on my Athlon 64)
use size_t and ssize_t instead of unsigned long et al use size_t and ssize_t instead of unsigned long et al
add iob_bytesleft
don't leak memory in test/httpd
0.24: 0.24:
fix scan_to_sa (Tim Lorenz) fix scan_to_sa (Tim Lorenz)

@ -0,0 +1,15 @@
.TH iob_bytesleft 3
.SH NAME
iob_bytesleft \- how many bytes are still to be sent?
.SH SYNTAX
.B #include <iob.h>
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)

@ -0,0 +1,5 @@
#include "iob.h"
uint64 iob_bytesleft(const io_batch* b) {
return b->bytesleft;
}

@ -33,5 +33,6 @@ int64 iob_write(int64 s,io_batch* b,io_write_callback cb);
void iob_reset(io_batch* b); void iob_reset(io_batch* b);
void iob_free(io_batch* b); void iob_free(io_batch* b);
void iob_prefetch(io_batch* b,uint64 bytes); void iob_prefetch(io_batch* b,uint64 bytes);
uint64 iob_bytesleft(const io_batch* b);
#endif #endif

@ -182,6 +182,16 @@ e404:
io_wantwrite(s); 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 main() {
int s=socket_tcp6b(); int s=socket_tcp6b();
uint32 scope_id; uint32 scope_id;
@ -242,6 +252,7 @@ int main() {
buffer_puts(buffer_2,"): "); buffer_puts(buffer_2,"): ");
buffer_puterror(buffer_2); buffer_puterror(buffer_2);
buffer_putnlflush(buffer_2); buffer_putnlflush(buffer_2);
cleanup(i);
io_close(i); io_close(i);
} else if (l==0) { } else if (l==0) {
if (h) { if (h) {
@ -252,6 +263,7 @@ int main() {
buffer_puts(buffer_2,"eof on fd #"); buffer_puts(buffer_2,"eof on fd #");
buffer_putulong(buffer_2,i); buffer_putulong(buffer_2,i);
buffer_putnlflush(buffer_2); buffer_putnlflush(buffer_2);
cleanup(i);
io_close(i); io_close(i);
} else if (l>0) { } else if (l>0) {
array_catb(&h->r,buf,l); array_catb(&h->r,buf,l);
@ -280,10 +292,12 @@ emerge:
if (h->keepalive) { if (h->keepalive) {
io_dontwantwrite(i); io_dontwantwrite(i);
io_wantread(i); io_wantread(i);
} else } else {
cleanup(i);
io_close(i); io_close(i);
} }
} }
} }
}
return 0; return 0;
} }

Loading…
Cancel
Save