summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix von Leitner <felix-libowfat@fefe.de>2018-03-12 13:04:30 +0000
committerFelix von Leitner <felix-libowfat@fefe.de>2018-03-12 13:04:30 +0000
commit49dea92f855b50f6beab035205164d683f791883 (patch)
treea1ef99b5d706478319414469ffe2f9b1652f239c
parent8eceaa5232964ead04ba7baea71801b8cb93aa70 (diff)
downloadlibowfat-49dea92f855b50f6beab035205164d683f791883.tar.gz
libowfat-49dea92f855b50f6beab035205164d683f791883.zip
use write in buffer_put for a slight perf improvement
-rw-r--r--CHANGES1
-rw-r--r--buffer/buffer_put.c24
-rw-r--r--dns/dns_rcrw.c1
-rw-r--r--dns/dns_transmit.c1
-rw-r--r--io/io_block.c11
-rw-r--r--io/io_nonblock.c1
-rw-r--r--mmap/mmap_read.32
-rw-r--r--mmap/mmap_readat.32
-rw-r--r--test/iob.c2
-rw-r--r--test/uudecode.c1
-rw-r--r--unix/iopause.c1
-rw-r--r--unix/ndelay_off.c1
-rw-r--r--unix/ndelay_on.c1
-rw-r--r--unix/winsock2errno.c1
14 files changed, 42 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 089679b..552282e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@
move headers to <libowfat/> upon install
fix fmt_ip6 (Erwin Hoffmann)
add MSG_ZEROCOPY support (only used for buffers >8k)
+ use write in buffer_put for a slight perf improvement
0.31:
special case buffer_get_token with token length 1 through memccpy (almost 4x speedup)
diff --git a/buffer/buffer_put.c b/buffer/buffer_put.c
index f38c66d..9ee9a0d 100644
--- a/buffer/buffer_put.c
+++ b/buffer/buffer_put.c
@@ -1,4 +1,8 @@
#include <string.h>
+#include <unistd.h>
+#ifndef __MINGW32__
+#include <sys/uio.h>
+#endif
#include "buffer.h"
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie);
@@ -13,12 +17,32 @@ extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,vo
int buffer_put(buffer* b,const char* buf,size_t len) {
if (__unlikely(len>b->a-b->p)) { /* doesn't fit */
+#ifndef __MINGW32__
+ if (b->op==write) {
+ /* if it's write, we can substitute writev */
+ struct iovec v[2];
+ ssize_t r;
+ v[0].iov_base=b->x; v[0].iov_len=b->p;
+ v[1].iov_base=(char*)buf; v[1].iov_len=len;
+ r=writev(b->fd,v,2);
+ if (r<0) return -1;
+ if ((size_t)r>=b->p) {
+ r-=b->p;
+ b->p=0;
+ buf+=r;
+ len-=r;
+ if (len) goto do_memcpy;
+ return 0;
+ } /* else fall through */
+ }
+#endif
if (buffer_flush(b)==-1) return -1;
if (len>b->a) {
if (buffer_stubborn(b->op,b->fd,buf,len,b)<0) return -1;
return 0;
}
}
+do_memcpy:
memcpy(b->x+b->p, buf, len);
b->p+=len;
return 0;
diff --git a/dns/dns_rcrw.c b/dns/dns_rcrw.c
index 68616b6..ee7318e 100644
--- a/dns/dns_rcrw.c
+++ b/dns/dns_rcrw.c
@@ -7,6 +7,7 @@
#include "dns.h"
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#endif
static stralloc data;
diff --git a/dns/dns_transmit.c b/dns/dns_transmit.c
index 9a8c015..fb3c335 100644
--- a/dns/dns_transmit.c
+++ b/dns/dns_transmit.c
@@ -1,6 +1,7 @@
#include <sys/types.h>
#ifdef WIN32
#include <winsock2.h>
+#include <windows.h>
#else
#include <sys/socket.h>
#endif
diff --git a/io/io_block.c b/io/io_block.c
index 3ccfb11..0b9a324 100644
--- a/io/io_block.c
+++ b/io/io_block.c
@@ -1,13 +1,14 @@
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "io_internal.h"
-
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#include "windoze.h"
#endif
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "io_internal.h"
+
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK
#endif
diff --git a/io/io_nonblock.c b/io/io_nonblock.c
index fa41a72..9a3b14c 100644
--- a/io/io_nonblock.c
+++ b/io/io_nonblock.c
@@ -5,6 +5,7 @@
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#include "windoze.h"
#endif
diff --git a/mmap/mmap_read.3 b/mmap/mmap_read.3
index 2379285..51d85df 100644
--- a/mmap/mmap_read.3
+++ b/mmap/mmap_read.3
@@ -4,7 +4,7 @@ mmap_read \- memory map a file for reading
.SH SYNTAX
.B #include <libowfat/mmap.h>
-char* \fBmmap_read\fP(const char* \fIfilename\fR,size_t* \fIfilesize\fR);
+const char* \fBmmap_read\fP(const char* \fIfilename\fR,size_t* \fIfilesize\fR);
.SH DESCRIPTION
mmap_read opens \fIfilename\fR for reading, maps the whole file into
memory, closes the file, writes the length of the file to \fIfilesize\fR
diff --git a/mmap/mmap_readat.3 b/mmap/mmap_readat.3
index 384fc1b..d0011be 100644
--- a/mmap/mmap_readat.3
+++ b/mmap/mmap_readat.3
@@ -4,7 +4,7 @@ mmap_readat \- memory map a file for reading
.SH SYNTAX
.B #include <libowfat/mmap.h>
-char* \fBmmap_readat\fP(const char* \fIfilename\fR,size_t* \fIfilesize\fR,int \fIdirfd\fR);
+const char* \fBmmap_readat\fP(const char* \fIfilename\fR,size_t* \fIfilesize\fR,int \fIdirfd\fR);
.SH DESCRIPTION
mmap_readat opens \fIfilename\fR for reading, maps the whole file into
memory, closes the file, writes the length of the file to \fIfilesize\fR
diff --git a/test/iob.c b/test/iob.c
index a2c6b1c..760401e 100644
--- a/test/iob.c
+++ b/test/iob.c
@@ -18,7 +18,7 @@ int main() {
assert(iob_addbuf(b," fnord\n",7));
assert(iob_addfile(b,fd,10,10));
iob_send(1,b);
-#if 0
+#if 1
do {
r=iob_write(1,b,write_cb);
} while (r>0);
diff --git a/test/uudecode.c b/test/uudecode.c
index 4b8d968..c5efdbb 100644
--- a/test/uudecode.c
+++ b/test/uudecode.c
@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <errno.h>
#include "textcode.h"
#include "str.h"
diff --git a/unix/iopause.c b/unix/iopause.c
index 316ea5b..3e4cd82 100644
--- a/unix/iopause.c
+++ b/unix/iopause.c
@@ -2,6 +2,7 @@
#include "iopause.h"
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#else
#include "select.h"
#endif
diff --git a/unix/ndelay_off.c b/unix/ndelay_off.c
index b26c89b..4c4312b 100644
--- a/unix/ndelay_off.c
+++ b/unix/ndelay_off.c
@@ -5,6 +5,7 @@
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#include "windoze.h"
#endif
diff --git a/unix/ndelay_on.c b/unix/ndelay_on.c
index 64e9036..c9e2f14 100644
--- a/unix/ndelay_on.c
+++ b/unix/ndelay_on.c
@@ -5,6 +5,7 @@
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#include "windoze.h"
#endif
diff --git a/unix/winsock2errno.c b/unix/winsock2errno.c
index c0cf71f..3a9d49c 100644
--- a/unix/winsock2errno.c
+++ b/unix/winsock2errno.c
@@ -1,5 +1,6 @@
#ifdef __MINGW32__
#include <winsock2.h>
+#include <windows.h>
#include <errno.h>
#include <stdio.h>
#include "socket.h"