mongoose7 wrote:CuteAlien has assumed the sockets are *blocking*. You can handle the problem simply with
Code: Select all
len = 0;
while (len < size) {
rv = recv( ... size - len ...);
if (rv <= 0) break;
len += rv;
}
A more sophisticated solution relies on more sophisticated methods.
Yes, the server sockets are blocking. The client sockets are not. My current send and recv methods are as follows, and using them does not change my current problem
Code: Select all
ssize_t sendAll(int sockfd, const void *buf, size_t len, int flags) {
ssize_t result;
char *pbuf = (char *)buf;
while ( len > 0 ) {
result = send(sockfd,pbuf,len,flags);
if ( result <= 0 ) break;
pbuf += result;
len -= result;
}
return result;
}
ssize_t recvAll(int sockfd, const void *buf, size_t len, int flags) {
u_long iMode=1;
ioctlsocket(sockfd,FIONBIO,&iMode);
ssize_t result;
char *pbuf = (char *)buf;
while ( len > 0 ) {
result = recv(sockfd,pbuf,len,flags);
if ( result <= 0 ) break;
pbuf += result;
len -= result;
}
return result;
}
The reason I think it's mixing the things up is because my server is sending "Incoming file" and the client receives it, then prepares for all incoming files. The server sends all the data stuff it needs.
But my client is
creating folders named " ß ß ß ß ß ß ß ß ß ß ß ß ß ß", "@@@ÿ@@@ÿ@@@ÿ", and "kG1ÿkG1ÿ^PHÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ@@@ÿ" which looks like things that should be in the file itself, not make new folders of the contents. It is creating the correct file(s) at first, though, and saving most of the content in them. And it seems to only happen with larger files
If I try to send a file with 835KB, it screws up like said above.
But sending a file with only 3KB works without any problems what-so-ever