2022-06-16 21:33:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "SocketBase.hpp"
|
2022-09-04 09:23:02 +00:00
|
|
|
#include "al/async/AsyncFunctorThread.h"
|
|
|
|
#include "heap/seadHeap.h"
|
2022-06-16 21:33:18 +00:00
|
|
|
#include "nn/result.h"
|
|
|
|
#include "sead/math/seadVector.h"
|
|
|
|
#include "sead/math/seadQuat.h"
|
|
|
|
#include "sead/container/seadPtrArray.h"
|
|
|
|
|
|
|
|
#include "al/util.hpp"
|
|
|
|
|
|
|
|
#include "nn/account.h"
|
|
|
|
|
|
|
|
#include "syssocket/sockdefines.h"
|
|
|
|
|
2022-09-04 09:23:02 +00:00
|
|
|
#include "thread/seadMessageQueue.h"
|
|
|
|
#include "thread/seadMutex.h"
|
2022-06-16 21:33:18 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "packets/Packet.h"
|
|
|
|
|
|
|
|
class SocketClient : public SocketBase {
|
|
|
|
public:
|
2022-09-04 09:23:02 +00:00
|
|
|
SocketClient(const char *name, sead::Heap *heap);
|
2022-07-05 19:45:22 +00:00
|
|
|
nn::Result init(const char* ip, u16 port) override;
|
2022-09-04 09:23:02 +00:00
|
|
|
bool tryReconnect();
|
2022-07-05 19:45:22 +00:00
|
|
|
bool closeSocket() override;
|
2022-09-04 09:23:02 +00:00
|
|
|
|
|
|
|
bool startThreads();
|
|
|
|
void endThreads();
|
|
|
|
|
|
|
|
bool send(Packet* packet);
|
|
|
|
bool recv();
|
|
|
|
|
|
|
|
bool queuePacket(Packet *packet);
|
|
|
|
void trySendQueue();
|
|
|
|
|
|
|
|
void sendFunc();
|
|
|
|
void recvFunc();
|
|
|
|
|
|
|
|
Packet *tryGetPacket(sead::MessageQueue::BlockType blockType = sead::MessageQueue::BlockType::Blocking);
|
|
|
|
|
2022-06-16 21:33:18 +00:00
|
|
|
void printPacket(Packet* packet);
|
2022-09-04 09:23:02 +00:00
|
|
|
bool isConnected() { return socket_log_state == SOCKET_LOG_CONNECTED; }
|
|
|
|
|
|
|
|
u32 getSendCount() { return mSendQueue.getCount(); }
|
|
|
|
u32 getSendMaxCount() { return mSendQueue.getMaxCount(); }
|
|
|
|
|
|
|
|
u32 getRecvCount() { return mRecvQueue.getCount(); }
|
|
|
|
u32 getRecvMaxCount() { return mRecvQueue.getMaxCount(); }
|
2022-06-16 21:33:18 +00:00
|
|
|
|
2022-09-04 09:23:02 +00:00
|
|
|
void setIsFirstConn(bool value) { mIsFirstConnect = value; }
|
2022-06-16 21:33:18 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-04 09:23:02 +00:00
|
|
|
sead::Heap* mHeap = nullptr;
|
|
|
|
|
|
|
|
al::AsyncFunctorThread* mRecvThread = nullptr;
|
|
|
|
al::AsyncFunctorThread* mSendThread = nullptr;
|
|
|
|
|
|
|
|
sead::MessageQueue mRecvQueue;
|
|
|
|
sead::MessageQueue mSendQueue;
|
|
|
|
|
2022-06-16 21:33:18 +00:00
|
|
|
int maxBufSize = 100;
|
2022-09-04 09:23:02 +00:00
|
|
|
bool mIsFirstConnect = true;
|
2022-07-10 06:13:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param str a string containing an IPv4 address or a hostname that can be resolved via DNS
|
|
|
|
* @param out IPv4 address
|
|
|
|
* @return if this function was successfull and out contains a valid IP address
|
|
|
|
*/
|
|
|
|
bool stringToIPAddress(const char* str, in_addr* out);
|
|
|
|
};
|
2022-09-04 09:23:02 +00:00
|
|
|
|
|
|
|
typedef void (SocketClient::*SocketThreadFunc)(void);
|