Beta2 is out! Total timeout works on Windows.
This commit is contained in:
parent
d914007507
commit
911e8d7e7f
9 changed files with 77 additions and 123 deletions
|
@ -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) {
|
||||
|
|
|
@ -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_ {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue