use write in buffer_put for a slight perf improvement

This commit is contained in:
leitner 2018-03-12 13:04:30 +00:00
parent d4d9b091ef
commit 94feba3667
14 changed files with 42 additions and 8 deletions

View File

@ -3,6 +3,7 @@
move headers to <libowfat/> upon install move headers to <libowfat/> upon install
fix fmt_ip6 (Erwin Hoffmann) fix fmt_ip6 (Erwin Hoffmann)
add MSG_ZEROCOPY support (only used for buffers >8k) add MSG_ZEROCOPY support (only used for buffers >8k)
use write in buffer_put for a slight perf improvement
0.31: 0.31:
special case buffer_get_token with token length 1 through memccpy (almost 4x speedup) special case buffer_get_token with token length 1 through memccpy (almost 4x speedup)

View File

@ -1,4 +1,8 @@
#include <string.h> #include <string.h>
#include <unistd.h>
#ifndef __MINGW32__
#include <sys/uio.h>
#endif
#include "buffer.h" #include "buffer.h"
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); 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) { int buffer_put(buffer* b,const char* buf,size_t len) {
if (__unlikely(len>b->a-b->p)) { /* doesn't fit */ 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 (buffer_flush(b)==-1) return -1;
if (len>b->a) { if (len>b->a) {
if (buffer_stubborn(b->op,b->fd,buf,len,b)<0) return -1; if (buffer_stubborn(b->op,b->fd,buf,len,b)<0) return -1;
return 0; return 0;
} }
} }
do_memcpy:
memcpy(b->x+b->p, buf, len); memcpy(b->x+b->p, buf, len);
b->p+=len; b->p+=len;
return 0; return 0;

View File

@ -7,6 +7,7 @@
#include "dns.h" #include "dns.h"
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#endif #endif
static stralloc data; static stralloc data;

View File

@ -1,6 +1,7 @@
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif

View File

@ -1,13 +1,14 @@
#ifdef __MINGW32__
#include <winsock2.h>
#include <windows.h>
#include "windoze.h"
#endif
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include "io_internal.h" #include "io_internal.h"
#ifdef __MINGW32__
#include <winsock2.h>
#include "windoze.h"
#endif
#ifndef O_NDELAY #ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK #define O_NDELAY O_NONBLOCK
#endif #endif

View File

@ -5,6 +5,7 @@
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#include "windoze.h" #include "windoze.h"
#endif #endif

View File

@ -4,7 +4,7 @@ mmap_read \- memory map a file for reading
.SH SYNTAX .SH SYNTAX
.B #include <libowfat/mmap.h> .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 .SH DESCRIPTION
mmap_read opens \fIfilename\fR for reading, maps the whole file into 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 memory, closes the file, writes the length of the file to \fIfilesize\fR

View File

@ -4,7 +4,7 @@ mmap_readat \- memory map a file for reading
.SH SYNTAX .SH SYNTAX
.B #include <libowfat/mmap.h> .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 .SH DESCRIPTION
mmap_readat opens \fIfilename\fR for reading, maps the whole file into 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 memory, closes the file, writes the length of the file to \fIfilesize\fR

View File

@ -18,7 +18,7 @@ int main() {
assert(iob_addbuf(b," fnord\n",7)); assert(iob_addbuf(b," fnord\n",7));
assert(iob_addfile(b,fd,10,10)); assert(iob_addfile(b,fd,10,10));
iob_send(1,b); iob_send(1,b);
#if 0 #if 1
do { do {
r=iob_write(1,b,write_cb); r=iob_write(1,b,write_cb);
} while (r>0); } while (r>0);

View File

@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include "textcode.h" #include "textcode.h"
#include "str.h" #include "str.h"

View File

@ -2,6 +2,7 @@
#include "iopause.h" #include "iopause.h"
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#else #else
#include "select.h" #include "select.h"
#endif #endif

View File

@ -5,6 +5,7 @@
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#include "windoze.h" #include "windoze.h"
#endif #endif

View File

@ -5,6 +5,7 @@
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#include "windoze.h" #include "windoze.h"
#endif #endif

View File

@ -1,5 +1,6 @@
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include "socket.h" #include "socket.h"