a few missing headers and minor fixes

fix corking behavior for the case where a buffer follows a buffer in
iob_send
master
leitner 9 years ago
parent cdecd16ab3
commit 7bdc1b29bb

@ -14,8 +14,7 @@ size_t fmt_iso8601(char* dest,time_t t) {
if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1; if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1;
/* "2014-05-27T19:22:16Z" */ /* "2014-05-27T19:22:16Z" */
i=fmt_2digits(dest,(x->tm_year+1900)/100); i=fmt_ulong(dest,(x->tm_year+1900));
i+=fmt_2digits(dest+i,(x->tm_year+1900)%100);
dest[i++]='-'; dest[i++]='-';
i+=fmt_2digits(dest+i,x->tm_mon+1); i+=fmt_2digits(dest+i,x->tm_mon+1);
dest[i++]='-'; dest[i++]='-';

@ -1,7 +1,7 @@
#include "io_internal.h" #include "io_internal.h"
#include <iarray.h> #include <iarray.h>
#include <fmt.h> #include <fmt.h>
#include <time.h> #include <sys/time.h>
unsigned int io_debugstring(int64 s,char* buf,unsigned int bufsize) { unsigned int io_debugstring(int64 s,char* buf,unsigned int bufsize) {
struct timeval tv; struct timeval tv;

@ -134,6 +134,9 @@ int64 iob_send(int64 s,io_batch* b) {
#ifdef HAVE_BSDSENDFILE #ifdef HAVE_BSDSENDFILE
long trailers; long trailers;
#endif #endif
#ifdef TCP_CORK
int corked=0;
#endif
if (b->bytesleft==0) return 0; if (b->bytesleft==0) return 0;
last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b)); last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b));
@ -202,8 +205,10 @@ eagain:
docork=-1; /* no files, only buffer, so no need for TCP_CORK or MSG_MORE */ docork=-1; /* no files, only buffer, so no need for TCP_CORK or MSG_MORE */
else else
docork=!(e+i+1==last); docork=!(e+i+1==last);
if (docork>0) if (docork>0) {
setsockopt(s,IPPROTO_TCP,TCP_CORK,(int[]){ 1 },sizeof(int)); setsockopt(s,IPPROTO_TCP,TCP_CORK,(int[]){ 1 },sizeof(int));
corked=1;
}
if (headers) { if (headers) {
if (docork<0) { /* write+writev */ if (docork<0) { /* write+writev */
if (headers==1) /* cosmetics for strace */ if (headers==1) /* cosmetics for strace */
@ -233,8 +238,8 @@ eagain:
#else /* !MSG_MORE */ #else /* !MSG_MORE */
#ifdef TCP_CORK #ifdef TCP_CORK
if (b->bufs && b->files && !b->next) { if (b->bufs && b->files && !b->next) {
static int one=1; setsockopt(s,IPPROTO_TCP,TCP_CORK,(int[]){ 1 },sizeof(int));
setsockopt(s,IPPROTO_TCP,TCP_CORK,&one,sizeof(one)); corked=1;
} }
#endif #endif
if (headers) { if (headers) {
@ -249,8 +254,9 @@ eagain:
} }
sent=-3; sent=-3;
} }
} else } else {
sent=io_sendfile(s,e->fd,e->offset,e->n); sent=io_sendfile(s,e->fd,e->offset,e->n);
}
#endif /* !MSG_MORE */ #endif /* !MSG_MORE */
#endif #endif
if (sent>0) if (sent>0)
@ -258,18 +264,6 @@ eagain:
else else
return total?total:(uint64)sent; return total?total:(uint64)sent;
if ((uint64)sent==b->bytesleft) { if ((uint64)sent==b->bytesleft) {
#ifdef MSG_MORE
if (docork==1) {
#endif
#ifdef TCP_CORK
if (b->bufs && b->files) {
static int zero=0;
setsockopt(s,IPPROTO_TCP,TCP_CORK,&zero,sizeof(zero));
}
#endif
#ifdef MSG_MORE
}
#endif
iob_reset(b); iob_reset(b);
break; break;
} else if (sent>0) { } else if (sent>0) {
@ -291,6 +285,10 @@ eagain:
} else break; } else break;
} }
abort: abort:
#ifdef TCP_CORK
if (corked)
setsockopt(s,IPPROTO_TCP,TCP_CORK,(int[]){ 0 },sizeof(int));
#endif
return total; return total;
} }

@ -23,4 +23,4 @@ any resources.
socket_connect6(s,ip,p,0); socket_connect6(s,ip,p,0);
.SH "SEE ALSO" .SH "SEE ALSO"
socket_bind4(3), socket_bind6(3) socket_tcp6b(3), socket_bind4(3), socket_bind6(3)

Loading…
Cancel
Save