aboutsummaryrefslogtreecommitdiff
path: root/src/wsocket.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
commit7c97e8e40aaa665226fb54449773dc3134e755b2 (patch)
tree47888d4c924fc24bf3b355bf58120ea3cdc74bc4 /src/wsocket.c
parenteb0fc857ddea6f084d338589e2a33d3e7d4eade6 (diff)
downloadluasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.gz
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.bz2
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.zip
Almost ready for beta3
Diffstat (limited to 'src/wsocket.c')
-rw-r--r--src/wsocket.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/wsocket.c b/src/wsocket.c
index 1b169ed..0294dce 100644
--- a/src/wsocket.c
+++ b/src/wsocket.c
@@ -180,9 +180,10 @@ int sock_accept(p_sock ps, p_sock pa, SA *addr, socklen_t *len, p_tm tm) {
180 180
181/*-------------------------------------------------------------------------*\ 181/*-------------------------------------------------------------------------*\
182* Send with timeout 182* Send with timeout
183* On windows, if you try to send 10MB, the OS will buffer EVERYTHING
184* this can take an awful lot of time and we will end up blocked.
185* Therefore, whoever calls this function should not pass a huge buffer.
183\*-------------------------------------------------------------------------*/ 186\*-------------------------------------------------------------------------*/
184/* has to be larger than UDP_DATAGRAMSIZE !!!*/
185#define MAXCHUNK (64*1024)
186int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) 187int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm)
187{ 188{
188 int err; 189 int err;
@@ -192,9 +193,7 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm)
192 *sent = 0; 193 *sent = 0;
193 for ( ;; ) { 194 for ( ;; ) {
194 /* try to send something */ 195 /* try to send something */
195 /* on windows, if you try to send 10MB, the OS will buffer EVERYTHING 196 int put = send(*ps, data, count, 0);
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);
198 /* if we sent something, we are done */ 197 /* if we sent something, we are done */
199 if (put > 0) { 198 if (put > 0) {
200 *sent = put; 199 *sent = put;
@@ -221,7 +220,7 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent,
221 if (*ps == SOCK_INVALID) return IO_CLOSED; 220 if (*ps == SOCK_INVALID) return IO_CLOSED;
222 *sent = 0; 221 *sent = 0;
223 for ( ;; ) { 222 for ( ;; ) {
224 int put = send(*ps, data, (int) count, 0); 223 int put = sendto(*ps, data, (int) count, 0, addr, len);
225 if (put > 0) { 224 if (put > 0) {
226 *sent = put; 225 *sent = put;
227 return IO_DONE; 226 return IO_DONE;
@@ -298,13 +297,13 @@ void sock_setnonblocking(p_sock ps) {
298int sock_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) { 297int sock_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
299 *hp = gethostbyaddr(addr, len, AF_INET); 298 *hp = gethostbyaddr(addr, len, AF_INET);
300 if (*hp) return IO_DONE; 299 if (*hp) return IO_DONE;
301 else return h_errno; 300 else return WSAGetLastError();
302} 301}
303 302
304int sock_gethostbyname(const char *addr, struct hostent **hp) { 303int sock_gethostbyname(const char *addr, struct hostent **hp) {
305 *hp = gethostbyname(addr); 304 *hp = gethostbyname(addr);
306 if (*hp) return IO_DONE; 305 if (*hp) return IO_DONE;
307 else return h_errno; 306 else return WSAGetLastError();
308} 307}
309 308
310/*-------------------------------------------------------------------------*\ 309/*-------------------------------------------------------------------------*\