From 911e8d7e7f63e6e90814e82955bfaf26328afb19 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 26 Jul 2004 05:17:37 +0000 Subject: Beta2 is out! Total timeout works on Windows. --- src/buffer.c | 8 ++++---- src/udp.h | 1 + src/wsocket.c | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/buffer.c b/src/buffer.c index a696158..dbd5d2c 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -81,10 +81,10 @@ int buf_meth_send(lua_State *L, p_buf buf) { const char *data = luaL_checklstring(L, 2, &size); long start = (long) luaL_optnumber(L, 3, 1); long end = (long) luaL_optnumber(L, 4, -1); - if (start < 0) start = size+start+1; - if (end < 0) end = size+end+1; - if (start < 1) start = 1; - if (end > (long) size) end = size; + if (start < 0) start = (long) (size+start+1); + if (end < 0) end = (long) (size+end+1); + if (start < 1) start = (long) 1; + if (end > (long) size) end = (long) size; if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); /* check if there was an error */ if (err != IO_DONE) { diff --git a/src/udp.h b/src/udp.h index f34c8ad..520573d 100644 --- a/src/udp.h +++ b/src/udp.h @@ -19,6 +19,7 @@ #include "timeout.h" #include "socket.h" +/* can't be larger than wsocket.c MAXCHUNK!!! */ #define UDP_DATAGRAMSIZE 8192 typedef struct t_udp_ { diff --git a/src/wsocket.c b/src/wsocket.c index 1f1e99d..1b169ed 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -181,6 +181,8 @@ int sock_accept(p_sock ps, p_sock pa, SA *addr, socklen_t *len, p_tm tm) { /*-------------------------------------------------------------------------*\ * Send with timeout \*-------------------------------------------------------------------------*/ +/* has to be larger than UDP_DATAGRAMSIZE !!!*/ +#define MAXCHUNK (64*1024) int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) { int err; @@ -190,7 +192,9 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) *sent = 0; for ( ;; ) { /* try to send something */ - int put = send(*ps, data, (int) count, 0); + /* on windows, if you try to send 10MB, the OS will buffer EVERYTHING + * this can take an awful lot of time and we will end up blocked. */ + int put = send(*ps, data, (count < MAXCHUNK)? (int)count: MAXCHUNK, 0); /* if we sent something, we are done */ if (put > 0) { *sent = put; -- cgit v1.2.3-55-g6feb