diff --git a/.cvsignore b/.cvsignore index 8a8ea69..c4b8f01 100644 --- a/.cvsignore +++ b/.cvsignore @@ -25,3 +25,4 @@ haveuint128.h ent tags entities.h +havepread.h diff --git a/CHANGES b/CHANGES index d0591bf..1938129 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 0.31: special case buffer_get_token with token length 1 through memccpy (almost 4x speedup) + test for pread and use it instead of lseek+read in cdb and io_mmapwritefile 0.30: add compiletimeassert.h diff --git a/GNUmakefile b/GNUmakefile index 10a2d96..574e3ed 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -133,6 +133,8 @@ dns_rcip.o dns_rcrw.o openreadclose.o: openreadclose.h iob_send.o scan_ip6if.o: havealloca.h +cdb.o io_mmapwritefile.o: havepread.h + # stoprip byte.a: $(BYTE_OBJS) @@ -194,7 +196,7 @@ clean: rm -f *.o *.a *.da *.bbg *.bb core t haveip6.h haven2i.h \ havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \ libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \ -dep libsocket havealloca.h haveuint128.h entities.h ent +dep libsocket havealloca.h haveuint128.h entities.h ent havepread.h INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \ uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \ @@ -302,6 +304,11 @@ haveuint128.h: tryuint128.c if $(DIET) $(CCC) $(CFLAGS) -c tryuint128.c >/dev/null 2>&1; then echo "#define HAVE_UINT128"; fi > $@ -rm -f tryuint128.o +havepread.h: trypread.c + -rm -f $@ + if $(DIET) $(CCC) $(CFLAGS) -c trypread.c >/dev/null 2>&1; then echo "#define HAVE_PREAD"; fi > $@ + -rm -f trypread.o + iopause.h: iopause.h1 iopause.h2 trypoll.c -rm -f $@ if $(DIET) $(CCC) $(CFLAGS) -o t trypoll.c >/dev/null 2>&1; then cp iopause.h2 iopause.h; else cp iopause.h1 iopause.h; fi diff --git a/Makefile b/Makefile index fdf9a77..c910d2a 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ case_diffs.o: case/case_diffs.c case.h case_lowerb.o: case/case_lowerb.c case.h case_lowers.o: case/case_lowers.c case.h case_starts.o: case/case_starts.c case.h -cdb.o: cdb/cdb.c byte.h cdb.h uint32.h uint64.h +cdb.o: cdb/cdb.c byte.h cdb.h uint32.h uint64.h havepread.h cdb_hash.o: cdb/cdb_hash.c cdb.h uint32.h uint64.h cdb_make.o: cdb/cdb_make.c cdb.h uint32.h uint64.h cdb_make.h buffer.h cdb_traverse.o: cdb/cdb_traverse.c cdb.h uint32.h uint64.h @@ -299,7 +299,7 @@ io_getcookie.o: io/io_getcookie.c io_internal.h io.h uint64.h taia.h \ havesigio.h io_mmapwritefile.o: io/io_mmapwritefile.c io_internal.h io.h uint64.h \ taia.h tai.h uint32.h array.h iarray.h haveepoll.h havekqueue.h \ - havedevpoll.h havesigio.h iob.h + havedevpoll.h havesigio.h iob.h havepread.h io_nonblock.o: io/io_nonblock.c io_internal.h io.h uint64.h taia.h tai.h \ uint32.h array.h iarray.h haveepoll.h havekqueue.h havedevpoll.h \ havesigio.h @@ -702,8 +702,8 @@ t.o: t.c fmt.h byte.h scan.h str.h uint16.h uint32.h stralloc.h socket.h \ critbit.h CAS.h io_internal.h haveepoll.h havekqueue.h havedevpoll.h \ havesigio.h BYTE_OBJS=byte_chr.o byte_copy.o byte_copyr.o byte_diff.o byte_equal_notimingattack.o byte_rchr.o byte_zero.o -FMT_OBJS=fmt_8long.o fmt_8longlong.o fmt_asn1derlength.o fmt_asn1dertag.o fmt_double.o fmt_escapecharc.o fmt_escapecharhtml.o fmt_escapecharjson.o fmt_escapecharquotedprintable.o fmt_escapecharquotedprintableutf8.o fmt_escapecharxml.o fmt_fill.o fmt_httpdate.o fmt_human.o fmt_humank.o fmt_long.o fmt_longlong.o fmt_minus.o fmt_pad.o fmt_plusminus.o fmt_str.o fmt_strm_internal.o fmt_strn.o fmt_tohex.o fmt_ulong.o fmt_ulong0.o fmt_ulonglong.o fmt_utf8.o fmt_xlong.o fmt_xlonglong.o fmt_xmlescape.o -SCAN_OBJS=scan_8int.o scan_8long.o scan_8longlong.o scan_8longn.o scan_8short.o scan_asn1derlength.o scan_asn1dertag.o scan_charsetnskip.o scan_double.o scan_fromhex.o scan_httpdate.o scan_int.o scan_long.o scan_longlong.o scan_longn.o scan_netstring.o scan_noncharsetnskip.o scan_nonwhitenskip.o scan_plusminus.o scan_short.o scan_uint.o scan_ulong.o scan_ulonglong.o scan_ulongn.o scan_ushort.o scan_utf8.o scan_whitenskip.o scan_xint.o scan_xlong.o scan_xlonglong.o scan_xlongn.o scan_xshort.o +FMT_OBJS=fmt_8long.o fmt_8longlong.o fmt_asn1derlength.o fmt_asn1dertag.o fmt_double.o fmt_escapecharc.o fmt_escapecharhtml.o fmt_escapecharjson.o fmt_escapecharquotedprintable.o fmt_escapecharquotedprintableutf8.o fmt_escapecharxml.o fmt_fill.o fmt_httpdate.o fmt_human.o fmt_humank.o fmt_iso8601.o fmt_long.o fmt_longlong.o fmt_minus.o fmt_netstring.o fmt_pad.o fmt_pb_double.o fmt_pb_float.o fmt_pb_int.o fmt_pb_sint.o fmt_pb_string.o fmt_pb_tag.o fmt_pb_type0_sint.o fmt_pb_type1_double.o fmt_pb_type1_fixed64.o fmt_pb_type2_string.o fmt_pb_type5_fixed32.o fmt_pb_type5_float.o fmt_plusminus.o fmt_str.o fmt_strm_internal.o fmt_strn.o fmt_tohex.o fmt_ulong.o fmt_ulong0.o fmt_ulonglong.o fmt_utf8.o fmt_varint.o fmt_xlong.o fmt_xlonglong.o fmt_xmlescape.o +SCAN_OBJS=scan_8int.o scan_8long.o scan_8longlong.o scan_8longn.o scan_8short.o scan_asn1derlength.o scan_asn1dertag.o scan_charsetnskip.o scan_double.o scan_fromhex.o scan_httpdate.o scan_int.o scan_iso8601.o scan_long.o scan_longlong.o scan_longn.o scan_netstring.o scan_noncharsetnskip.o scan_nonwhitenskip.o scan_pb_tag.o scan_pb_type0_sint.o scan_pb_type1_double.o scan_pb_type1_fixed64.o scan_pb_type2_stringlen.o scan_pb_type5_fixed32.o scan_pb_type5_float.o scan_plusminus.o scan_short.o scan_uint.o scan_ulong.o scan_ulonglong.o scan_ulongn.o scan_ushort.o scan_utf8.o scan_varint.o scan_whitenskip.o scan_xint.o scan_xlong.o scan_xlonglong.o scan_xlongn.o scan_xshort.o STR_OBJS=str_chr.o str_copy.o str_diff.o str_diffn.o str_len.o str_rchr.o str_start.o UINT_OBJS=uint16_pack.o uint16_pack_big.o uint16_read.o uint16_read_big.o uint16_unpack.o uint16_unpack_big.o uint32_pack.o uint32_pack_big.o uint32_read.o uint32_read_big.o uint32_unpack.o uint32_unpack_big.o uint64_pack.o uint64_pack_big.o uint64_read.o uint64_read_big.o uint64_unpack.o uint64_unpack_big.o OPEN_OBJS=open_append.o open_excl.o open_read.o open_rw.o open_trunc.o open_write.o openreadclose.o readclose.o @@ -719,7 +719,7 @@ CASE_OBJS=case_diffb.o case_diffs.o case_lowerb.o case_lowers.o case_starts.o MULT_OBJS=imult16.o imult32.o imult64.o range_arrayinbuf.o range_str2inbuf.o range_str4inbuf.o range_strinbuf.o umult16.o umult32.o umult64.o ARRAY_OBJS=array_allocate.o array_bytes.o array_cat.o array_cat0.o array_catb.o array_cate.o array_cats.o array_cats0.o array_equal.o array_fail.o array_get.o array_length.o array_reset.o array_start.o array_trunc.o array_truncate.o iarray_allocate.o iarray_free.o iarray_get.o iarray_init.o iarray_length.o IO_OBJS=io_appendfile.o io_block.o io_canread.o io_canwrite.o io_check.o io_close.o io_closeonexec.o io_createfile.o io_debugstring.o io_dontwantread.o io_dontwantwrite.o io_eagain.o io_eagain_read.o io_eagain_write.o io_fd.o io_finishandshutdown.o io_getcookie.o io_mmapwritefile.o io_nonblock.o io_passfd.o io_pipe.o io_readfile.o io_readwritefile.o io_receivefd.o io_sendfile.o io_setcookie.o io_sigpipe.o io_socketpair.o io_timedout.o io_timeout.o io_timeouted.o io_tryread.o io_tryreadtimeout.o io_trywrite.o io_trywritetimeout.o io_wait.o io_waitread.o io_waituntil.o io_waituntil2.o io_waitwrite.o io_wantread.o io_wantwrite.o iob_addbuf.o iob_addbuf_free.o iob_addbuf_internal.o iob_addbuf_munmap.o iob_addfile.o iob_addfile_close.o iob_adds.o iob_adds_free.o iob_bytesleft.o iob_free.o iob_new.o iob_prefetch.o iob_reset.o iob_send.o iob_write.o -TEXTCODE_OBJS=base64.o fmt_base64.o fmt_cescape.o fmt_foldwhitespace.o fmt_hexdump.o fmt_html.o fmt_html_tagarg.o fmt_jsonescape.o fmt_ldapescape.o fmt_ldapescape2.o fmt_quotedprintable.o fmt_to_array.o fmt_to_sa.o fmt_tofrom_array.o fmt_urlencoded.o fmt_uuencoded.o fmt_xml.o fmt_yenc.o scan_base64.o scan_cescape.o scan_hexdump.o scan_html.o scan_jsonescape.o scan_ldapescape.o scan_quotedprintable.o scan_to_array.o scan_to_sa.o scan_tofrom_array.o scan_urlencoded.o scan_uuencoded.o scan_yenc.o +TEXTCODE_OBJS=base64.o base64url.o fmt_base64.o fmt_base64url.o fmt_cescape.o fmt_foldwhitespace.o fmt_hexdump.o fmt_html.o fmt_html_tagarg.o fmt_jsonescape.o fmt_ldapescape.o fmt_ldapescape2.o fmt_quotedprintable.o fmt_to_array.o fmt_to_sa.o fmt_tofrom_array.o fmt_urlencoded.o fmt_uuencoded.o fmt_xml.o fmt_yenc.o scan_base64.o scan_base64url.o scan_cescape.o scan_hexdump.o scan_html.o scan_jsonescape.o scan_ldapescape.o scan_quotedprintable.o scan_to_array.o scan_to_sa.o scan_tofrom_array.o scan_urlencoded.o scan_uuencoded.o scan_yenc.o CDB_OBJS=cdb.o cdb_hash.o cdb_make.o cdb_traverse.o CRITBIT_OBJS=critbit.o @@ -782,7 +782,7 @@ clean: rm -f *.o *.a *.da *.bbg *.bb core t haveip6.h haven2i.h \ havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \ libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \ -dep libsocket havealloca.h haveuint128.h entities.h ent +dep libsocket havealloca.h haveuint128.h entities.h ent havepread.h INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \ uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \ @@ -890,6 +890,11 @@ haveuint128.h: tryuint128.c if $(DIET) $(CCC) $(CFLAGS) -c tryuint128.c >/dev/null 2>&1; then echo "#define HAVE_UINT128"; fi > $@ -rm -f tryuint128.o +havepread.h: trypread.c + -rm -f $@ + if $(DIET) $(CCC) $(CFLAGS) -c trypread.c >/dev/null 2>&1; then echo "#define HAVE_PREAD"; fi > $@ + -rm -f trypread.o + iopause.h: iopause.h1 iopause.h2 trypoll.c -rm -f $@ if $(DIET) $(CCC) $(CFLAGS) -o t trypoll.c >/dev/null 2>&1; then cp iopause.h2 iopause.h; else cp iopause.h1 iopause.h; fi diff --git a/cdb/cdb.c b/cdb/cdb.c index 1c55de8..cbba320 100644 --- a/cdb/cdb.c +++ b/cdb/cdb.c @@ -6,6 +6,7 @@ #include #include "byte.h" #include "cdb.h" +#include "havepread.h" #ifdef __MINGW32__ #include "windows.h" #else @@ -63,16 +64,25 @@ int cdb_read(struct cdb *c,unsigned char *buf,unsigned long len,uint32 pos) { byte_copy(buf,len,c->map + pos); } else { +#ifndef HAVE_PREAD if (lseek(c->fd,pos,SEEK_SET) == -1) return -1; +#endif while (len > 0) { - int r; + ssize_t r; do +#ifdef HAVE_PREAD + r = pread(c->fd,buf,len,pos); +#else r = read(c->fd,buf,len); +#endif while ((r == -1) && (errno == EINTR)); if (r == -1) return -1; if (r == 0) goto FORMAT; buf += r; len -= r; +#ifdef HAVE_PREAD + pos += r; +#endif } } return 0; diff --git a/io/io_mmapwritefile.c b/io/io_mmapwritefile.c index dd649b2..964c29b 100644 --- a/io/io_mmapwritefile.c +++ b/io/io_mmapwritefile.c @@ -8,12 +8,13 @@ #include #endif #include +#include "havepread.h" #define BUFSIZE 16384 int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callback writecb) { char buf[BUFSIZE]; - int n,m; + ssize_t n,m; uint64 sent=0; io_entry* e=iarray_get(&io_fds,out); if (e) { @@ -92,12 +93,20 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb return sent; } readwrite: +#ifndef HAVE_PREAD if (lseek(in,off,SEEK_SET) != (off_t)off) return -1; +#endif while (bytes>0) { char* tmp=buf; +#ifdef HAVE_PREAD + if ((n=pread(in,tmp,(bytes0) { if ((m=writecb(out,tmp,n))<0) { if (m==-1) {