make sure the mmap based io_sendfile actually works (and terminates)

master
leitner 21 years ago
parent 3fe23979fd
commit 3cac9c2b80

@ -60,13 +60,12 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
if (off>=e->mapofs && off<e->mapofs+e->maplen) if (off>=e->mapofs && off<e->mapofs+e->maplen)
goto mapok; /* ok; mmapped the right chunk*/ goto mapok; /* ok; mmapped the right chunk*/
munmap(e->mmapped,e->maplen); munmap(e->mmapped,e->maplen);
e->mmapped=0;
} }
e->mapofs=off&0xffffffffffff0000ull; e->mapofs=off&0xffffffffffff0000ull;
if (e->mapofs+0xffff>off+bytes) if (e->mapofs+0x10000>off+bytes)
e->maplen=off+bytes-e->mapofs; e->maplen=off+bytes-e->mapofs;
else else
e->maplen=0xffff; e->maplen=0x10000;
if ((e->mmapped=mmap(0,e->maplen,PROT_READ,MAP_SHARED,in,e->mapofs))==MAP_FAILED) { if ((e->mmapped=mmap(0,e->maplen,PROT_READ,MAP_SHARED,in,e->mapofs))==MAP_FAILED) {
e->mmapped=0; e->mmapped=0;
goto readwrite; goto readwrite;

7
t.c

@ -23,12 +23,19 @@
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
int main(int argc,char* argv[]) { int main(int argc,char* argv[]) {
char buf[100];
int i;
printf("%d\n",i=fmt_pad(buf,"fnord",5,7,10));
buf[i]=0;
puts(buf);
#if 0
char ip[16]; char ip[16];
char buf[32]; char buf[32];
printf("%d (expect 2)\n",scan_ip6("::",ip)); printf("%d (expect 2)\n",scan_ip6("::",ip));
printf("%d (expect 3)\n",scan_ip6("::1",ip)); printf("%d (expect 3)\n",scan_ip6("::1",ip));
printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip)); printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip));
printf("%.*s\n",fmt_ip6(buf,ip),buf); printf("%.*s\n",fmt_ip6(buf,ip),buf);
#endif
#if 0 #if 0
static stralloc s,t; static stralloc s,t;
stralloc_copys(&s,"fnord"); stralloc_copys(&s,"fnord");

Loading…
Cancel
Save