diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer.c | 8 | ||||
-rw-r--r-- | src/udp.h | 1 | ||||
-rw-r--r-- | src/wsocket.c | 6 |
3 files changed, 10 insertions, 5 deletions
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) { | |||
81 | const char *data = luaL_checklstring(L, 2, &size); | 81 | const char *data = luaL_checklstring(L, 2, &size); |
82 | long start = (long) luaL_optnumber(L, 3, 1); | 82 | long start = (long) luaL_optnumber(L, 3, 1); |
83 | long end = (long) luaL_optnumber(L, 4, -1); | 83 | long end = (long) luaL_optnumber(L, 4, -1); |
84 | if (start < 0) start = size+start+1; | 84 | if (start < 0) start = (long) (size+start+1); |
85 | if (end < 0) end = size+end+1; | 85 | if (end < 0) end = (long) (size+end+1); |
86 | if (start < 1) start = 1; | 86 | if (start < 1) start = (long) 1; |
87 | if (end > (long) size) end = size; | 87 | if (end > (long) size) end = (long) size; |
88 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); | 88 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); |
89 | /* check if there was an error */ | 89 | /* check if there was an error */ |
90 | if (err != IO_DONE) { | 90 | if (err != IO_DONE) { |
@@ -19,6 +19,7 @@ | |||
19 | #include "timeout.h" | 19 | #include "timeout.h" |
20 | #include "socket.h" | 20 | #include "socket.h" |
21 | 21 | ||
22 | /* can't be larger than wsocket.c MAXCHUNK!!! */ | ||
22 | #define UDP_DATAGRAMSIZE 8192 | 23 | #define UDP_DATAGRAMSIZE 8192 |
23 | 24 | ||
24 | typedef struct t_udp_ { | 25 | 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) { | |||
181 | /*-------------------------------------------------------------------------*\ | 181 | /*-------------------------------------------------------------------------*\ |
182 | * Send with timeout | 182 | * Send with timeout |
183 | \*-------------------------------------------------------------------------*/ | 183 | \*-------------------------------------------------------------------------*/ |
184 | /* has to be larger than UDP_DATAGRAMSIZE !!!*/ | ||
185 | #define MAXCHUNK (64*1024) | ||
184 | int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) | 186 | int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) |
185 | { | 187 | { |
186 | int err; | 188 | int err; |
@@ -190,7 +192,9 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) | |||
190 | *sent = 0; | 192 | *sent = 0; |
191 | for ( ;; ) { | 193 | for ( ;; ) { |
192 | /* try to send something */ | 194 | /* try to send something */ |
193 | int put = send(*ps, data, (int) count, 0); | 195 | /* on windows, if you try to send 10MB, the OS will buffer EVERYTHING |
196 | * this can take an awful lot of time and we will end up blocked. */ | ||
197 | int put = send(*ps, data, (count < MAXCHUNK)? (int)count: MAXCHUNK, 0); | ||
194 | /* if we sent something, we are done */ | 198 | /* if we sent something, we are done */ |
195 | if (put > 0) { | 199 | if (put > 0) { |
196 | *sent = put; | 200 | *sent = put; |