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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save