mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-22 03:05:16 +00:00
Convert receive buffer to be on heap
This commit is contained in:
parent
bf646b2b3d
commit
4a5a10f910
3 changed files with 9 additions and 8 deletions
|
@ -10,7 +10,7 @@
|
||||||
#define PACKBUFSIZE 0x30
|
#define PACKBUFSIZE 0x30
|
||||||
#define COSTUMEBUFSIZE 0x20
|
#define COSTUMEBUFSIZE 0x20
|
||||||
|
|
||||||
#define MAXPACKSIZE 0x100
|
#define MAXPACKSIZE 0x50
|
||||||
|
|
||||||
enum PacketType : short {
|
enum PacketType : short {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
|
|
|
@ -64,6 +64,7 @@ class SocketClient : public SocketBase {
|
||||||
|
|
||||||
sead::MessageQueue mRecvQueue;
|
sead::MessageQueue mRecvQueue;
|
||||||
sead::MessageQueue mSendQueue;
|
sead::MessageQueue mSendQueue;
|
||||||
|
char* recvBuf = nullptr;
|
||||||
|
|
||||||
int maxBufSize = 100;
|
int maxBufSize = 100;
|
||||||
bool mIsFirstConnect = true;
|
bool mIsFirstConnect = true;
|
||||||
|
|
|
@ -21,6 +21,7 @@ SocketClient::SocketClient(const char* name, sead::Heap* heap) : mHeap(heap), So
|
||||||
|
|
||||||
mRecvQueue.allocate(maxBufSize, mHeap);
|
mRecvQueue.allocate(maxBufSize, mHeap);
|
||||||
mSendQueue.allocate(maxBufSize, mHeap);
|
mSendQueue.allocate(maxBufSize, mHeap);
|
||||||
|
recvBuf = (char*)mHeap->alloc(MAXPACKSIZE+1);
|
||||||
};
|
};
|
||||||
|
|
||||||
nn::Result SocketClient::init(const char* ip, u16 port) {
|
nn::Result SocketClient::init(const char* ip, u16 port) {
|
||||||
|
@ -198,7 +199,6 @@ bool SocketClient::recv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int headerSize = sizeof(Packet);
|
int headerSize = sizeof(Packet);
|
||||||
char headerBuf[MAXPACKSIZE + 1] = {0};
|
|
||||||
int valread = 0;
|
int valread = 0;
|
||||||
|
|
||||||
const int fd_count = 2;
|
const int fd_count = 2;
|
||||||
|
@ -229,12 +229,12 @@ bool SocketClient::recv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == 1) {
|
if (index == 1) {
|
||||||
int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags);
|
int result = nn::socket::Recv(fd, recvBuf, sizeof(MAXPACKSIZE), this->sock_flags);
|
||||||
if (result < headerSize){
|
if (result < headerSize){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet* header = reinterpret_cast<Packet*>(headerBuf);
|
Packet* header = reinterpret_cast<Packet*>(recvBuf);
|
||||||
int fullSize = header->mPacketSize + sizeof(Packet);
|
int fullSize = header->mPacketSize + sizeof(Packet);
|
||||||
// Verify packet size is appropriate
|
// Verify packet size is appropriate
|
||||||
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
||||||
|
@ -251,7 +251,7 @@ bool SocketClient::recv() {
|
||||||
|
|
||||||
char* packetBuf = (char*)mHeap->alloc(fullSize);
|
char* packetBuf = (char*)mHeap->alloc(fullSize);
|
||||||
if (packetBuf){
|
if (packetBuf){
|
||||||
memcpy(packetBuf, headerBuf, fullSize);
|
memcpy(packetBuf, recvBuf, fullSize);
|
||||||
|
|
||||||
|
|
||||||
Packet *packet = reinterpret_cast<Packet*>(packetBuf);
|
Packet *packet = reinterpret_cast<Packet*>(packetBuf);
|
||||||
|
@ -268,7 +268,7 @@ bool SocketClient::recv() {
|
||||||
// read only the size of a header
|
// read only the size of a header
|
||||||
while(valread < headerSize) {
|
while(valread < headerSize) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
result = nn::socket::Recv(fd, headerBuf + valread,
|
result = nn::socket::Recv(fd, recvBuf + valread,
|
||||||
headerSize - valread, this->sock_flags);
|
headerSize - valread, this->sock_flags);
|
||||||
|
|
||||||
this->socket_errno = nn::socket::GetLastErrno();
|
this->socket_errno = nn::socket::GetLastErrno();
|
||||||
|
@ -286,7 +286,7 @@ bool SocketClient::recv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(valread > 0) {
|
if(valread > 0) {
|
||||||
Packet* header = reinterpret_cast<Packet*>(headerBuf);
|
Packet* header = reinterpret_cast<Packet*>(recvBuf);
|
||||||
|
|
||||||
int fullSize = header->mPacketSize + sizeof(Packet);
|
int fullSize = header->mPacketSize + sizeof(Packet);
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ bool SocketClient::recv() {
|
||||||
|
|
||||||
if (packetBuf) {
|
if (packetBuf) {
|
||||||
|
|
||||||
memcpy(packetBuf, headerBuf, sizeof(Packet));
|
memcpy(packetBuf, recvBuf, sizeof(Packet));
|
||||||
|
|
||||||
while (valread < fullSize) {
|
while (valread < fullSize) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue