Revision: 9628 http://pure-data.svn.sourceforge.net/pure-data/?rev=9628&view=rev Author: mrpeach Date: 2008-03-27 12:56:13 -0700 (Thu, 27 Mar 2008)
Log Message: ----------- No limit on sendable file size.
Modified Paths: -------------- trunk/externals/mrpeach/net/tcpserver.c
Modified: trunk/externals/mrpeach/net/tcpserver.c =================================================================== --- trunk/externals/mrpeach/net/tcpserver.c 2008-03-27 19:32:39 UTC (rev 9627) +++ trunk/externals/mrpeach/net/tcpserver.c 2008-03-27 19:56:13 UTC (rev 9628) @@ -108,6 +108,7 @@ static void tcpserver_socketreceiver_free(t_tcpserver_socketreceiver *x); static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv); static void tcp_server_send_bytes(int sockfd, t_tcpserver *x, int argc, t_atom *argv); +static size_t tcpserver_send_buf(int client, int sockfd, char *byte_buf, size_t length); static void tcpserver_client_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv); static void tcpserver_disconnect(t_tcpserver *x); static void tcpserver_client_disconnect(t_tcpserver *x, t_floatarg fclient); @@ -291,14 +292,8 @@ int i, j, d; unsigned char c; float f, e; - char *bp; - int length, sent; - int result; - static double lastwarntime; - static double pleasewarn; - double timebefore; - double timeafter; - int late; + int length; + size_t flen; int sockfd = x->x_fd[client]; char fpath[FILENAME_MAX]; FILE *fptr; @@ -357,13 +352,14 @@ #endif if (j >= MAX_UDP_RECEIVE) { - post ("%s: file too long, truncating at %lu", objName, MAX_UDP_RECEIVE); - break; + flen += tcpserver_send_buf(client, sockfd, byte_buf, j); + j = 0; } } + flen += j; fclose(fptr); fptr = NULL; - post("%s: read "%s" length %d byte%s", objName, fpath, j, ((d==1)?"":"s")); + post("%s: read "%s" length %d byte%s", objName, fpath, flen, ((d==1)?"":"s")); } else { @@ -374,38 +370,53 @@ length = j; if (length > 0) { - for (bp = byte_buf, sent = 0; sent < length;) + tcpserver_send_buf(client, sockfd, byte_buf, length); + } + } + else post("%s: not a valid socket number (%d)", objName, sockfd); +} + +static size_t tcpserver_send_buf(int client, int sockfd, char *byte_buf, size_t length) +{ + char *bp; + size_t sent; + double timebefore; + static double lastwarntime; + static double pleasewarn; + int result; + int late; + double timeafter; + + for (bp = byte_buf, sent = 0; sent < length;) + { + timebefore = sys_getrealtime(); + result = send(sockfd, byte_buf, (int)(length-sent), 0); + timeafter = sys_getrealtime(); + late = (timeafter - timebefore > 0.005); + if (late || pleasewarn) + { + if (timeafter > lastwarntime + 2) { - timebefore = sys_getrealtime(); - result = send(sockfd, byte_buf, length-sent, 0); - timeafter = sys_getrealtime(); - late = (timeafter - timebefore > 0.005); - if (late || pleasewarn) - { - if (timeafter > lastwarntime + 2) - { - post("%s: send blocked %d msec", objName, - (int)(1000 * ((timeafter - timebefore) + pleasewarn))); - pleasewarn = 0; - lastwarntime = timeafter; - } - else if (late) pleasewarn += timeafter - timebefore; - } - if (result <= 0) - { - sys_sockerror("tcpserver: send"); - post("%s: could not send data to client %d", objName, client); - break; - } - else - { - sent += result; - bp += result; - } + post("%s: send blocked %d msec", objName, + (int)(1000 * ((timeafter - timebefore) + pleasewarn))); + pleasewarn = 0; + lastwarntime = timeafter; } + else if (late) pleasewarn += timeafter - timebefore; } + if (result <= 0) + { + sys_sockerror("tcpserver: send"); + post("%s: could not send data to client %d", objName, client); + break; + } + else + { + sent += result; + bp += result; + } } - else post("%s: not a valid socket number (%d)", objName, sockfd); + return sent; }
/* send message to client using socket number */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.