fixed receive from wiiload and other application that send the header one byte at a time

This commit is contained in:
dimok789 2016-03-14 18:16:03 +01:00
parent 875969f851
commit e688b5ee91
3 changed files with 39 additions and 3 deletions

View File

@ -9,6 +9,7 @@
#include "fs/CFile.hpp"
#include "utils/logger.h"
#include "utils/StringTools.h"
#include "utils/net.h"
TcpReceiver::TcpReceiver(int port)
: GuiFrame(0, 0)
@ -96,13 +97,14 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
u32 fileSize = 0;
u32 fileSizeUnc = 0;
unsigned char haxx[8];
memset(haxx, 0, sizeof(haxx));
//skip haxx
recv(clientSocket, haxx, 8, 0);
recv(clientSocket, &fileSize, 4, 0);
recvwait(clientSocket, haxx, sizeof(haxx));
recvwait(clientSocket, (unsigned char*)&fileSize, sizeof(fileSize));
if (haxx[4] > 0 || haxx[5] > 4)
{
recv(clientSocket, &fileSizeUnc, 4, 0); // Compressed protocol, read another 4 bytes
recvwait(clientSocket, (unsigned char*)&fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
}
u32 bytesRead = 0;

20
src/utils/net.c Normal file
View File

@ -0,0 +1,20 @@
#include "dynamic_libs/socket_functions.h"
int recvwait(int sock, unsigned char *buffer, int len)
{
int recvBytes = 0;
while(len)
{
int ret = recv(sock, buffer, len, 0);
if(ret <= 0) {
return ret;
}
len -= ret;
buffer += ret;
recvBytes += ret;
}
return recvBytes;
}

14
src/utils/net.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __NET_H_
#define __NET_H_
#ifdef __cplusplus
extern "C" {
#endif
int recvwait(int sock, unsigned char *buffer, int len);
#ifdef __cplusplus
}
#endif
#endif