Formatting and cleanup

This commit is contained in:
Maschell 2021-09-24 21:04:06 +02:00
parent e7cb6b4572
commit feb1e5237c
13 changed files with 77 additions and 91 deletions

View File

@ -1,12 +1,11 @@
#include <stdarg.h> #include <cstdarg>
#include <stdlib.h> #include <cstdio>
#include <stdio.h>
#include <strings.h> #include <strings.h>
#include <fs/CFile.hpp> #include <fs/CFile.hpp>
CFile::CFile() { CFile::CFile() {
iFd = -1; iFd = -1;
mem_file = NULL; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }

View File

@ -1,9 +1,8 @@
#ifndef CFILE_HPP_ #pragma once
#define CFILE_HPP_
#include <stdio.h> #include <cstdio>
#include <string> #include <string>
#include <string.h> #include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <wut_types.h> #include <wut_types.h>
@ -29,7 +28,7 @@ public:
int32_t open(const uint8_t *memory, int32_t memsize); int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const { [[nodiscard]] BOOL isOpen() const {
if (iFd >= 0) if (iFd >= 0)
return true; return true;
@ -49,11 +48,11 @@ public:
int32_t seek(long int offset, int32_t origin); int32_t seek(long int offset, int32_t origin);
uint64_t tell() { [[nodiscard]] uint64_t tell() const {
return pos; return pos;
}; };
uint64_t size() { [[nodiscard]] uint64_t size() const {
return filesize; return filesize;
}; };
@ -67,5 +66,3 @@ protected:
uint64_t filesize; uint64_t filesize;
uint64_t pos; uint64_t pos;
}; };
#endif

View File

@ -80,7 +80,7 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
if (folderpath.size() < 3) if (folderpath.size() < 3)
return false; return false;
struct dirent *dirent = NULL; struct dirent *dirent = nullptr;
DIR *dir = NULL; DIR *dir = NULL;
dir = opendir(folderpath.c_str()); dir = opendir(folderpath.c_str());
@ -152,7 +152,7 @@ void DirList::ClearList() {
for (uint32_t i = 0; i < FileInfo.size(); ++i) { for (uint32_t i = 0; i < FileInfo.size(); ++i) {
if (FileInfo[i].FilePath) { if (FileInfo[i].FilePath) {
free(FileInfo[i].FilePath); free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL; FileInfo[i].FilePath = nullptr;
} }
} }
@ -191,7 +191,7 @@ void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
} }
uint64_t DirList::GetFilesize(int32_t index) const { uint64_t DirList::GetFilesize(int32_t index) const {
struct stat st; struct stat st{};
const char *path = GetFilepath(index); const char *path = GetFilepath(index);
if (!path || stat(path, &st) != 0) if (!path || stat(path, &st) != 0)
@ -204,7 +204,7 @@ int32_t DirList::GetFileIndex(const char *filename) const {
if (!filename) if (!filename)
return -1; return -1;
for (uint32_t i = 0; i < FileInfo.size(); ++i) { for (int32_t i = 0; i < FileInfo.size(); ++i) {
if (strcasecmp(GetFilename(i), filename) == 0) if (strcasecmp(GetFilename(i), filename) == 0)
return i; return i;
} }

View File

@ -24,8 +24,7 @@
* DirList Class * DirList Class
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#ifndef ___DIRLIST_H_ #pragma once
#define ___DIRLIST_H_
#include <vector> #include <vector>
#include <string> #include <string>
@ -39,43 +38,43 @@ typedef struct {
class DirList { class DirList {
public: public:
//!Constructor //!Constructor
DirList(void); DirList();
//!\param path Path from where to load the filelist of all files //!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered //!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum //!\param flags search/filter flags from the enum
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); explicit DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//!Destructor //!Destructor
virtual ~DirList(); virtual ~DirList();
//! Load all the files from a directory //! Load all the files from a directory
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//! Get a filename of the list //! Get a filename of the list
//!\param list index //!\param list index
const char *GetFilename(int32_t index) const; [[nodiscard]] const char *GetFilename(int32_t index) const;
//! Get the a filepath of the list //! Get the a filepath of the list
//!\param list index //!\param list index
const char *GetFilepath(int32_t index) const { [[nodiscard]] const char *GetFilepath(int32_t index) const {
if (!valid(index)) return ""; if (!valid(index)) return "";
else return FileInfo[index].FilePath; else return FileInfo[index].FilePath;
} }
//! Get the a filesize of the list //! Get the a filesize of the list
//!\param list index //!\param list index
uint64_t GetFilesize(int32_t index) const; [[nodiscard]] uint64_t GetFilesize(int32_t index) const;
//! Is index a dir or a file //! Is index a dir or a file
//!\param list index //!\param list index
BOOL IsDir(int32_t index) const { [[nodiscard]] BOOL IsDir(int32_t index) const {
if (!valid(index)) return false; if (!valid(index)) return false;
return FileInfo[index].isDir; return FileInfo[index].isDir;
}; };
//! Get the filecount of the whole list //! Get the filecount of the whole list
int32_t GetFilecount() const { [[nodiscard]] int32_t GetFilecount() const {
return FileInfo.size(); return FileInfo.size();
}; };
@ -105,14 +104,12 @@ protected:
void ClearList(); void ClearList();
//! Check if valid pos is requested //! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const { [[nodiscard]] inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size()); return (pos < FileInfo.size());
}; };
uint32_t Flags; uint32_t Flags{};
uint32_t Depth; uint32_t Depth{};
const char *Filter; const char *Filter{};
std::vector<DirEntry> FileInfo; std::vector<DirEntry> FileInfo;
}; };
#endif

View File

@ -9,7 +9,7 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input //! always initialze input
*inbuffer = NULL; *inbuffer = nullptr;
if (size) if (size)
*size = 0; *size = 0;
@ -20,8 +20,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
uint32_t filesize = lseek(iFd, 0, SEEK_END); uint32_t filesize = lseek(iFd, 0, SEEK_END);
lseek(iFd, 0, SEEK_SET); lseek(iFd, 0, SEEK_SET);
uint8_t *buffer = (uint8_t *) malloc(filesize); auto *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) { if (buffer == nullptr) {
close(iFd); close(iFd);
return -2; return -2;
} }
@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
if (done != filesize) { if (done != filesize) {
free(buffer); free(buffer);
buffer = NULL; buffer = nullptr;
return -3; return -3;
} }
@ -62,7 +62,7 @@ int32_t FSUtils::CheckFile(const char *filepath) {
if (!filepath) if (!filepath)
return 0; return 0;
struct stat filestat; struct stat filestat{};
char dirnoslash[strlen(filepath) + 2]; char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
@ -106,7 +106,7 @@ int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if (!ptr) { if (!ptr) {
//!Device root directory (must be with '/') //!Device root directory (must be with '/')
strcat(parentpath, "/"); strcat(parentpath, "/");
struct stat filestat; struct stat filestat{};
if (stat(parentpath, &filestat) == 0) if (stat(parentpath, &filestat) == 0)
return 1; return 1;

View File

@ -1,8 +1,6 @@
#include <wups.h> #include <wups.h>
#include "utils/TcpReceiver.h" #include "utils/TcpReceiver.h"
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <coreinit/cache.h>
#include <sysapp/launch.h>
WUPS_PLUGIN_NAME("Wiiload"); WUPS_PLUGIN_NAME("Wiiload");
WUPS_PLUGIN_DESCRIPTION("Wiiload Server"); WUPS_PLUGIN_DESCRIPTION("Wiiload Server");

View File

@ -4,10 +4,9 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdint.h> #include <cstdint>
#include <nsysnet/socket.h> #include <nsysnet/socket.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -14,8 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#ifndef CTHREAD_H_ #pragma once
#define CTHREAD_H_
#include <malloc.h> #include <malloc.h>
#include <unistd.h> #include <unistd.h>
@ -28,7 +27,7 @@ public:
typedef void (*Callback)(CThread *thread, void *arg); typedef void (*Callback)(CThread *thread, void *arg);
//! constructor //! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) { : pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment //! save attribute assignment
iAttributes = iAttr; iAttributes = iAttr;
@ -52,24 +51,24 @@ public:
} }
//! Get thread ID //! Get thread ID
virtual void *getThread() const { [[nodiscard]] virtual void *getThread() const {
return pThread; return pThread;
} }
//! Thread entry function //! Thread entry function
virtual void executeThread(void) { virtual void executeThread() {
if (pCallback) if (pCallback)
pCallback(this, pCallbackArg); pCallback(this, pCallbackArg);
} }
//! Suspend thread //! Suspend thread
virtual void suspendThread(void) { virtual void suspendThread() {
if (isThreadSuspended()) return; if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread); if (pThread) OSSuspendThread(pThread);
} }
//! Resume thread //! Resume thread
virtual void resumeThread(void) { virtual void resumeThread() {
if (!isThreadSuspended()) return; if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread); if (pThread) OSResumeThread(pThread);
} }
@ -80,30 +79,30 @@ public:
} }
//! Check if thread is suspended //! Check if thread is suspended
virtual BOOL isThreadSuspended(void) const { [[nodiscard]] virtual BOOL isThreadSuspended() const {
if (pThread) return OSIsThreadSuspended(pThread); if (pThread) return OSIsThreadSuspended(pThread);
return false; return false;
} }
//! Check if thread is terminated //! Check if thread is terminated
virtual BOOL isThreadTerminated(void) const { [[nodiscard]] virtual BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread); if (pThread) return OSIsThreadTerminated(pThread);
return false; return false;
} }
//! Check if thread is running //! Check if thread is running
virtual BOOL isThreadRunning(void) const { [[nodiscard]] virtual BOOL isThreadRunning() const {
return !isThreadSuspended() && !isThreadRunning(); return !isThreadSuspended() && !isThreadRunning();
} }
//! Shutdown thread //! Shutdown thread
virtual void shutdownThread(void) { virtual void shutdownThread() {
//! wait for thread to finish //! wait for thread to finish
if (pThread && !(iAttributes & eAttributeDetach)) { if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended()) if (isThreadSuspended())
resumeThread(); resumeThread();
OSJoinThread(pThread, NULL); OSJoinThread(pThread, nullptr);
} }
//! free the thread stack buffer //! free the thread stack buffer
if (pThreadStack) if (pThreadStack)
@ -111,18 +110,18 @@ public:
if (pThread) if (pThread)
free(pThread); free(pThread);
pThread = NULL; pThread = nullptr;
pThreadStack = NULL; pThreadStack = nullptr;
} }
//! Thread attributes //! Thread attributes
enum eCThreadAttributes { enum eCThreadAttributes {
eAttributeNone = 0x07, eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01, eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02, eAttributeAffCore1 = 0x02,
eAttributeAffCore2 = 0x04, eAttributeAffCore2 = 0x04,
eAttributeDetach = 0x08, eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10 eAttributePinnedAff = 0x10
}; };
private: private:
static int threadCallback(int argc, const char **argv) { static int threadCallback(int argc, const char **argv) {
@ -137,5 +136,3 @@ private:
Callback pCallback; Callback pCallback;
void *pCallbackArg; void *pCallbackArg;
}; };
#endif

View File

@ -34,7 +34,7 @@ void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, uint32_t);
} }
TcpReceiver::TcpReceiver(int32_t port) TcpReceiver::TcpReceiver(int32_t port)
: CThread(CThread::eAttributeAffCore1, 16,0x20000), exitRequested(false), serverPort(port), serverSocket(-1) { : CThread(CThread::eAttributeAffCore1, 16, 0x20000), exitRequested(false), serverPort(port), serverSocket(-1) {
resumeThread(); resumeThread();
} }
@ -58,7 +58,7 @@ void TcpReceiver::executeThread() {
uint32_t enable = 1; uint32_t enable = 1;
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
struct sockaddr_in bindAddress; struct sockaddr_in bindAddress{};
memset(&bindAddress, 0, sizeof(bindAddress)); memset(&bindAddress, 0, sizeof(bindAddress));
bindAddress.sin_family = AF_INET; bindAddress.sin_family = AF_INET;
bindAddress.sin_port = serverPort; bindAddress.sin_port = serverPort;
@ -76,7 +76,7 @@ void TcpReceiver::executeThread() {
return; return;
} }
struct sockaddr_in clientAddr; struct sockaddr_in clientAddr{};
memset(&clientAddr, 0, sizeof(clientAddr)); memset(&clientAddr, 0, sizeof(clientAddr));
int32_t addrlen = sizeof(struct sockaddr); int32_t addrlen = sizeof(struct sockaddr);
@ -91,9 +91,9 @@ void TcpReceiver::executeThread() {
close(clientSocket); close(clientSocket);
if (result > 0) if (result > 0)
if (result >= 0){ if (result >= 0) {
break; break;
} }
} else { } else {
DEBUG_FUNCTION_LINE("Server socket accept failed %i %d", clientSocket, errno); DEBUG_FUNCTION_LINE("Server socket accept failed %i %d", clientSocket, errno);
OSSleepTicks(OSMicrosecondsToTicks(100000)); OSSleepTicks(OSMicrosecondsToTicks(100000));
@ -105,6 +105,7 @@ void TcpReceiver::executeThread() {
extern bool gDoRelaunch; extern bool gDoRelaunch;
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress); DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress);
@ -120,13 +121,13 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
} }
struct in_addr in; struct in_addr in{};
uint32_t bytesRead = 0; uint32_t bytesRead = 0;
in.s_addr = ipAddress; in.s_addr = ipAddress;
DEBUG_FUNCTION_LINE("transfer start"); DEBUG_FUNCTION_LINE("transfer start");
unsigned char *loadAddress = (unsigned char *) memalign(0x40, fileSize); auto *loadAddress = (unsigned char *) memalign(0x40, fileSize);
if (!loadAddress) { if (!loadAddress) {
OSSleepTicks(OSSecondsToTicks(1)); OSSleepTicks(OSSecondsToTicks(1));
return NOT_ENOUGH_MEMORY; return NOT_ENOUGH_MEMORY;
@ -160,7 +161,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
// Do we need to unzip this thing? // Do we need to unzip this thing?
if (haxx[4] > 0 || haxx[5] > 4) { if (haxx[4] > 0 || haxx[5] > 4) {
unsigned char *inflatedData = NULL; unsigned char *inflatedData = nullptr;
// We need to unzip... // We need to unzip...
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) { if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) {
@ -233,7 +234,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
FSUtils::CreateSubfolder(RPX_TEMP_PATH); FSUtils::CreateSubfolder(RPX_TEMP_PATH);
res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE, inflatedData, fileSize); res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE, inflatedData, fileSize);
file_path = WUHB_TEMP_FILE_EX; file_path = WUHB_TEMP_FILE_EX;
if(!res){ if (!res) {
// temp.wuhb might be mounted, let's try temp2.wuhb // temp.wuhb might be mounted, let's try temp2.wuhb
res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE_2, inflatedData, fileSize); res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE_2, inflatedData, fileSize);
file_path = WUHB_TEMP_FILE_2_EX; file_path = WUHB_TEMP_FILE_2_EX;
@ -253,7 +254,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
std::vector<PluginContainer> finalList; std::vector<PluginContainer> finalList;
finalList.push_back(newContainer.value()); finalList.push_back(newContainer.value());
for (auto &plugin : oldPlugins) { for (auto &plugin: oldPlugins) {
if (plugin.metaInformation.getName() == newContainer->metaInformation.getName() && if (plugin.metaInformation.getName() == newContainer->metaInformation.getName() &&
plugin.metaInformation.getAuthor() == newContainer->metaInformation.getAuthor() plugin.metaInformation.getAuthor() == newContainer->metaInformation.getAuthor()
) { ) {
@ -265,7 +266,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
} }
} }
for (auto &plugin : finalList) { for (auto &plugin: finalList) {
DEBUG_FUNCTION_LINE("name: %s", plugin.getMetaInformation().getName().c_str()); DEBUG_FUNCTION_LINE("name: %s", plugin.getMetaInformation().getName().c_str());
DEBUG_FUNCTION_LINE("author: %s", plugin.getMetaInformation().getAuthor().c_str()); DEBUG_FUNCTION_LINE("author: %s", plugin.getMetaInformation().getAuthor().c_str());
DEBUG_FUNCTION_LINE("handle: %08X", plugin.getPluginData().getHandle()); DEBUG_FUNCTION_LINE("handle: %08X", plugin.getPluginData().getHandle());

View File

@ -17,20 +17,18 @@ public:
NOT_A_VALID_PLUGIN = -5, NOT_A_VALID_PLUGIN = -5,
}; };
TcpReceiver(int32_t port); explicit TcpReceiver(int32_t port);
~TcpReceiver(); ~TcpReceiver() override;
//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart; //sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
//sigslot::signal3<GuiElement *, uint32_t, int32_t> serverReceiveFinished; //sigslot::signal3<GuiElement *, uint32_t, int32_t> serverReceiveFinished;
private: private:
void executeThread(); void executeThread() override;
int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress); static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
bool saveFileToSDCard(const char *path, void *buffer, uint32_t size);
bool exitRequested; bool exitRequested;
int32_t serverPort; int32_t serverPort;

View File

@ -16,11 +16,11 @@ extern "C" {
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0); } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0); } while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7,6 +7,7 @@ int32_t recvwait(int32_t sock, void *buffer, int32_t len) {
while (socket_lock) { while (socket_lock) {
usleep(1000); usleep(1000);
} }
socket_lock = 1;
int32_t ret; int32_t ret;
while (len > 0) { while (len > 0) {
ret = recv(sock, buffer, len, 0); ret = recv(sock, buffer, len, 0);
@ -45,6 +46,7 @@ int32_t checkbyte(int32_t sock) {
while (socket_lock) { while (socket_lock) {
usleep(1000); usleep(1000);
} }
socket_lock = 1;
unsigned char buffer[1]; unsigned char buffer[1];
int32_t ret; int32_t ret;
@ -61,6 +63,7 @@ int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
while (socket_lock) { while (socket_lock) {
usleep(1000); usleep(1000);
} }
socket_lock = 1;
int32_t ret; int32_t ret;
while (len > 0) { while (len > 0) {
// For some reason the send blocks/crashes if the buffer is too big.. // For some reason the send blocks/crashes if the buffer is too big..

View File

@ -1,5 +1,4 @@
#ifndef _UTILS_NET_H_ #pragma once
#define _UTILS_NET_H_
#include <stdint.h> #include <stdint.h>
@ -33,5 +32,3 @@ int32_t sendbyte(int32_t sock, unsigned char byte);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif