version 1.3, 2015/04/20 18:19:52
|
version 1.4, 2015/09/25 20:24:20
|
|
|
#include <sock/sock.h> | #include <sock/sock.h> |
#include <sock/selector.h> | #include <sock/selector.h> |
#include <pal/sleep.h> | #include <pal/sleep.h> |
|
#include <pal/intsafe.h> |
#include <base/buf.h> | #include <base/buf.h> |
#include <base/log.h> | #include <base/log.h> |
#include <base/result.h> | #include <base/result.h> |
|
|
| |
} | } |
| |
|
size_t allocSize = 0; |
|
if (SizeTAdd(sizeof(Page), handler->recvHeaders.contentLength, &allocSize) == S_OK && |
|
SizeTAdd(allocSize, 1, &allocSize) == S_OK) |
|
{ |
/* Allocate zero-terminated buffer */ | /* Allocate zero-terminated buffer */ |
handler->recvPage = (Page*)PAL_Malloc(sizeof(Page) + handler->recvHeaders.contentLength + 1); |
handler->recvPage = (Page*)PAL_Malloc(allocSize); |
|
} |
|
else |
|
{ |
|
// Overflow |
|
return PRT_RETURN_FALSE; |
|
} |
| |
if (!handler->recvPage) | if (!handler->recvPage) |
return PRT_RETURN_FALSE; | return PRT_RETURN_FALSE; |
|
|
| |
if (mask & SELECTOR_READ) | if (mask & SELECTOR_READ) |
{ | { |
int count; |
|
|
|
for (count = 0; count < 5; count++) |
|
{ |
|
/* Accept the incoming connection */ | /* Accept the incoming connection */ |
r = Sock_Accept(handler->base.sock, &s, &addr); | r = Sock_Accept(handler->base.sock, &s, &addr); |
| |
|
|
Sock_Close(s); | Sock_Close(s); |
return MI_TRUE; | return MI_TRUE; |
} | } |
|
|
} | } |
| |
/* Watch for read events on the incoming connection */ | /* Watch for read events on the incoming connection */ |
|
|
NULL, | NULL, |
MI_TRUE ); | MI_TRUE ); |
} | } |
} |
|
| |
if ((mask & SELECTOR_REMOVE) != 0 || | if ((mask & SELECTOR_REMOVE) != 0 || |
(mask & SELECTOR_DESTROY) != 0) | (mask & SELECTOR_DESTROY) != 0) |
|
|
/* Run the selector */ | /* Run the selector */ |
return Selector_Run(self->selector, timeoutUsec, MI_FALSE); | return Selector_Run(self->selector, timeoutUsec, MI_FALSE); |
} | } |
|
|