From 264ad29f22d976e89bcb9c7a1e781415560bdd2c Mon Sep 17 00:00:00 2001 From: Luke Ceddia Date: Sat, 30 Jan 2016 19:10:14 +1100 Subject: [PATCH] Make tcp_out try harder to send data. The function now interprets the return value from send() and recalls if needed to transmit all data. --- internal/c/libqb.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 145f505e5..745bace47 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -22975,6 +22975,7 @@ int32 func__printwidth(qbs* text, int32 screenhandle, int32 passed){ //Referenced: http://johnnie.jerrata.com/winsocktutorial/ + //Much of the unix sockets code based on http://beej.us/guide/bgnet/ #ifdef QB64_WINDOWS #include WSADATA wsaData; @@ -23250,21 +23251,22 @@ int32 func__printwidth(qbs* text, int32 screenhandle, int32 passed){ void tcp_out(void *connection,void *offset,ptrszint bytes){ #if !defined(DEPENDENCY_SOCKETS) #elif defined(QB64_WINDOWS) || defined(QB64_LINUX) - static tcp_connection *tcp; tcp=(tcp_connection*)connection; - static int nret; - //should check nret to make sure all data is sent - //MSG_NOSIGNAL? - nret = send(tcp->socket, - (char*)offset, - bytes, - 0); + tcp_connection *tcp; tcp=(tcp_connection*)connection; + int total = 0; // how many bytes we've sent + int bytesleft = bytes; // how many we have left to send + int n; + + while(total < bytes) { + n = send(tcp->socket, (char*)(offset + total), bytesleft, 0); + if (n == -1) break; + total += n; + bytesleft -= n; + } + //if (n == -1) error occured. #else #endif - } - - int32 cloud_port_redirect=-1; struct connection_struct{ int8 in_use;//0=not being used, 1=in use