Browse Source

add iob_bytesleft

don't leak memory in test/httpd.c
master
Felix von Leitner 15 years ago
parent
commit
51609b5628
  1. 2
      CHANGES
  2. 15
      io/iob_bytesleft.3
  3. 5
      io/iob_bytesleft.c
  4. 1
      iob.h
  5. 16
      test/httpd.c

2
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)

15
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 <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)

5
io/iob_bytesleft.c

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

1
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

16
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);
}
}
}
}

Loading…
Cancel
Save