use write in buffer_put for a slight perf improvement

master
leitner 7 years ago
parent d4d9b091ef
commit 94feba3667

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

@ -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;

@ -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;

@ -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

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

@ -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

@ -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

@ -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

@ -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);

@ -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"

@ -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

@ -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

@ -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

@ -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"

Loading…
Cancel
Save