Skip to content

Commit

Permalink
SOCK_SEND now tracks if all bytes have been successfully sent,
Browse files Browse the repository at this point in the history
if not will poll and try again.  Increased version to 1.1.3
  • Loading branch information
jaryan committed Dec 14, 2011
1 parent bffbeff commit 88ac800
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: websockets
Type: Package
Title: HTML 5 Websocket Interface for R
Version: 1.1.2
Version: 1.1.3
Date: 2011-09-13
Author: B. W. Lewis <blewis@illposed.net>
Maintainer: B. W. Lewis <blewis@illposed.net>
Expand Down
19 changes: 12 additions & 7 deletions src/libsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,25 @@ SEXP SOCK_SEND(SEXP S, SEXP DATA)
{
struct pollfd pfds;
int h;
const void *data = (const void *)RAW(DATA);
size_t len = (size_t)length(DATA);
int s = INTEGER(S)[0];
int ts = 0, // total sent
sent = 0;
pfds.fd = s;
pfds.events = POLLOUT;
h = poll(&pfds, 1, 500);
if(h<1) return ScalarInteger(-1);
if(pfds.events & POLLOUT)
while(ts < len) {
h = poll(&pfds, 1, 500);
if(h<1) return ScalarInteger(-1);
if(pfds.events & POLLOUT) {
#ifdef WIN32
return ScalarInteger(send((SOCKET)s, data, len, 0));
sent = send((SOCKET)s, (const void *)&(RAW(DATA)[ts]), len-ts, 0);
#else
return ScalarInteger(send(s, data, len, 0));
sent = send(s, (const void *)&(RAW(DATA)[ts]), len-ts, 0);
#endif
return ScalarInteger(-1);
ts+=sent;
} else return ScalarInteger(-1);
}
return ScalarInteger(ts);
}

/* A generic recv wrapper function */
Expand Down

0 comments on commit 88ac800

Please sign in to comment.