2017-05-07 14:44:09 +02:00
|
|
|
#include "ControllerPatcherNet.hpp"
|
2017-10-29 09:34:47 +01:00
|
|
|
#include <dynamic_libs/os_functions.h>
|
|
|
|
#include <dynamic_libs/socket_functions.h>
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ControllerPatcherNet::recvwait(s32 sock, void *buffer, s32 len) {
|
|
|
|
s32 ret;
|
2017-03-30 17:53:36 +02:00
|
|
|
while (len > 0) {
|
|
|
|
ret = recv(sock, buffer, len, 0);
|
|
|
|
if(ret < 0) return ret;
|
|
|
|
len -= ret;
|
2017-04-06 12:49:50 +02:00
|
|
|
buffer = (void *)(((char *) buffer) + ret);
|
2017-03-30 17:53:36 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-10 15:39:58 +02:00
|
|
|
u8 ControllerPatcherNet::recvbyte(s32 sock) {
|
2017-03-30 17:53:36 +02:00
|
|
|
unsigned char buffer[1];
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ret;
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
ret = recvwait(sock, buffer, 1);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
return buffer[0];
|
|
|
|
}
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ControllerPatcherNet::checkbyte(s32 sock) {
|
2017-03-30 17:53:36 +02:00
|
|
|
unsigned char buffer[1];
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ret;
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
ret = recv(sock, buffer, 1, MSG_DONTWAIT);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
if (ret == 0) return -1;
|
|
|
|
return buffer[0];
|
|
|
|
}
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ControllerPatcherNet::sendwait(s32 sock, const void *buffer, s32 len) {
|
|
|
|
s32 ret;
|
2017-03-30 17:53:36 +02:00
|
|
|
while (len > 0) {
|
|
|
|
ret = send(sock, buffer, len, 0);
|
|
|
|
if(ret < 0) return ret;
|
|
|
|
len -= ret;
|
2017-04-06 12:49:50 +02:00
|
|
|
buffer = (void *)(((char *) buffer) + ret);
|
2017-03-30 17:53:36 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 ControllerPatcherNet::sendbyte(s32 sock, unsigned char byte) {
|
2017-03-30 17:53:36 +02:00
|
|
|
unsigned char buffer[1];
|
|
|
|
buffer[0] = byte;
|
|
|
|
return sendwait(sock, buffer, 1);
|
|
|
|
}
|