Skip to content

Commit ca171aa

Browse files
committed
packet framework + reorganize some files
1 parent 19e868f commit ca171aa

File tree

94 files changed

+1329
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1329
-570
lines changed

include/revolution/SO/SOCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ typedef enum {
7272

7373
typedef enum {
7474
SO_SO_REUSEADDR = 0x0004,
75-
SO_SO_SNDBUF = 0x1002,
76-
SO_SO_RCVBUF = 0x1003,
75+
SO_SO_SNDBUF = 0x1001,
76+
SO_SO_RCVBUF = 0x1002,
7777
} SOSockOpt;
7878

7979
typedef enum { SO_SHUT_RD, SO_SHUT_WR, SO_SHUT_RDWR } SOShutdownType;
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <libkiwi/prim/kiwiBitCast.h>
2-
31
#include <libkiwi.h>
42

53
namespace kiwi {
@@ -8,37 +6,38 @@ namespace detail {
86
/**
97
* @brief Constructor
108
*/
11-
ThreadImpl::ThreadImpl() : mpOSThread(nullptr), mpThreadStack(nullptr) {
9+
StdThreadImpl::StdThreadImpl() : mpOSThread(nullptr), mpThreadStack(nullptr) {
1210
// Thread & stack aligned to 32
1311
mpOSThread = new (32) OSThread();
1412
K_ASSERT_PTR(mpOSThread);
1513
mpThreadStack = new (32) u8[scStackSize];
1614
K_ASSERT_PTR(mpThreadStack);
1715

18-
BOOL success =
19-
OSCreateThread(mpOSThread, nullptr, nullptr,
20-
mpThreadStack + scStackSize, scStackSize, scPriority, 0);
16+
BOOL success = OSCreateThread(mpOSThread, nullptr, nullptr,
17+
mpThreadStack + scStackSize, scStackSize,
18+
OS_PRIORITY_MAX - 1, 0);
19+
2120
K_ASSERT(success);
2221
}
2322

2423
/**
2524
* @brief Destructor
2625
*/
27-
ThreadImpl::~ThreadImpl() {
26+
StdThreadImpl::~StdThreadImpl() {
2827
K_ASSERT_PTR(mpOSThread);
2928
K_ASSERT_EX(*mpOSThread->stackEnd == OS_THREAD_STACK_MAGIC,
3029
"Thread stack overflow!!!");
3130

3231
OSDetachThread(mpOSThread);
3332

3433
delete mpOSThread;
35-
delete mpThreadStack;
34+
delete[] mpThreadStack;
3635
}
3736

3837
/**
3938
* @brief Begins execution on this thread
4039
*/
41-
void ThreadImpl::Start() {
40+
void StdThreadImpl::Start() {
4241
K_ASSERT_PTR(mpOSThread);
4342
K_ASSERT(mpOSThread->state == OS_THREAD_STATE_READY);
4443
K_ASSERT_EX(mpOSThread->context.srr0 != 0, "No function to call");
@@ -51,7 +50,7 @@ void ThreadImpl::Start() {
5150
/**
5251
* @brief Waits for this thread to finish executing
5352
*/
54-
void ThreadImpl::Join() {
53+
void StdThreadImpl::Join() {
5554
K_ASSERT_PTR(mpOSThread);
5655

5756
BOOL success = OSJoinThread(mpOSThread, nullptr);
@@ -63,7 +62,7 @@ void ThreadImpl::Join() {
6362
*
6463
* @param addr Function address (new SRR0 value)
6564
*/
66-
void ThreadImpl::SetFunction(const void* addr) {
65+
void StdThreadImpl::SetFunction(const void* addr) {
6766
K_ASSERT_PTR(mpOSThread);
6867
K_ASSERT(addr != 0);
6968
mpOSThread->context.srr0 = BitCast<u32>(addr);
@@ -75,7 +74,7 @@ void ThreadImpl::SetFunction(const void* addr) {
7574
* @param i GPR number
7675
* @param value New value
7776
*/
78-
void ThreadImpl::SetGPR(u32 idx, u32 value) {
77+
void StdThreadImpl::SetGPR(u32 idx, u32 value) {
7978
K_ASSERT_PTR(mpOSThread);
8079
K_ASSERT(idx >= 0 && idx < K_LENGTHOF(mpOSThread->context.gprs));
8180
mpOSThread->context.gprs[idx] = value;
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LIBKIWI_CORE_THREAD_H
2-
#define LIBKIWI_CORE_THREAD_H
1+
#ifndef LIBKIWI_CORE_STD_THREAD_H
2+
#define LIBKIWI_CORE_STD_THREAD_H
33
#include <libkiwi/debug/kiwiAssert.h>
44
#include <libkiwi/k_types.h>
55

@@ -16,7 +16,7 @@ namespace detail {
1616
/**
1717
* @brief Common thread implementation
1818
*/
19-
class ThreadImpl {
19+
class StdThreadImpl {
2020
public:
2121
/**
2222
* @brief Waits for this thread to finish executing
@@ -27,11 +27,11 @@ class ThreadImpl {
2727
/**
2828
* @brief Constructor
2929
*/
30-
ThreadImpl();
30+
StdThreadImpl();
3131
/**
3232
* @brief Destructor
3333
*/
34-
~ThreadImpl();
34+
~StdThreadImpl();
3535

3636
/**
3737
* @brief Begins execution on this thread
@@ -77,7 +77,7 @@ class ThreadImpl {
7777
* @details Similar to std::thread.
7878
* @note Only allows GPR arguments
7979
*/
80-
class Thread : public detail::ThreadImpl {
80+
class StdThread : public detail::StdThreadImpl {
8181
public:
8282
// Thread function parameter
8383
typedef void* Param;
@@ -92,14 +92,14 @@ class Thread : public detail::ThreadImpl {
9292
*
9393
* @param pFunc Static, no-parameter function
9494
*/
95-
template <typename TRet> Thread(TRet (*pFunc)());
95+
template <typename TRet> StdThread(TRet (*pFunc)());
9696
/**
9797
* @brief Constructor
9898
*
9999
* @param pFunc Static, single-parameter function
100100
* @param pArg Function argument
101101
*/
102-
template <typename TRet> Thread(TRet (*pFunc)(Param), Param pArg);
102+
template <typename TRet> StdThread(TRet (*pFunc)(Param), Param pArg);
103103
/**@}*/
104104

105105
/**
@@ -113,7 +113,7 @@ class Thread : public detail::ThreadImpl {
113113
* @param rObj Class instance
114114
*/
115115
template <typename TRet, typename TClass>
116-
Thread(TRet (TClass::*pFunc)(), TClass& rObj);
116+
StdThread(TRet (TClass::*pFunc)(), TClass& rObj);
117117
/**
118118
* @brief Constructor
119119
*
@@ -122,7 +122,7 @@ class Thread : public detail::ThreadImpl {
122122
* @param pArg Function argument
123123
*/
124124
template <typename TRet, typename TClass>
125-
Thread(TRet (TClass::*pFunc)(Param), TClass& rObj, Param pArg);
125+
StdThread(TRet (TClass::*pFunc)(Param), TClass& rObj, Param pArg);
126126
/**@}*/
127127

128128
/**
@@ -136,7 +136,7 @@ class Thread : public detail::ThreadImpl {
136136
* @param rObj Class instance
137137
*/
138138
template <typename TRet, typename TClass>
139-
Thread(TRet (TClass::*pFunc)() const, const TClass& rObj);
139+
StdThread(TRet (TClass::*pFunc)() const, const TClass& rObj);
140140
/**
141141
* @brief Constructor
142142
*
@@ -145,7 +145,8 @@ class Thread : public detail::ThreadImpl {
145145
* @param pArg Function argument
146146
*/
147147
template <typename TRet, typename TClass>
148-
Thread(TRet (TClass::*pFunc)(Param) const, const TClass& rObj, Param pArg);
148+
StdThread(TRet (TClass::*pFunc)(Param) const, const TClass& rObj,
149+
Param pArg);
149150
/**@}*/
150151
};
151152

@@ -154,7 +155,7 @@ class Thread : public detail::ThreadImpl {
154155

155156
// Implementation header
156157
#ifndef LIBKIWI_CORE_THREAD_IMPL_HPP
157-
#include <libkiwi/core/kiwiThreadImpl.hpp>
158+
#include <libkiwi/core/kiwiStdThreadImpl.hpp>
158159
#endif
159160

160161
#endif
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Implementation header
2-
#ifndef LIBKIWI_CORE_THREAD_IMPL_HPP
3-
#define LIBKIWI_CORE_THREAD_IMPL_HPP
2+
#ifndef LIBKIWI_CORE_STD_THREAD_IMPL_HPP
3+
#define LIBKIWI_CORE_STD_THREAD_IMPL_HPP
44

55
// Declaration header
6-
#ifndef LIBKIWI_CORE_THREAD_H
7-
#include <libkiwi/core/kiwiThread.h>
6+
#ifndef LIBKIWI_CORE_STD_THREAD_H
7+
#include <libkiwi/core/kiwiStdThread.h>
88
#endif
99

1010
#include <libkiwi/prim/kiwiBitCast.h>
@@ -22,7 +22,7 @@ namespace kiwi {
2222
*
2323
* @param pFunc Static, no-parameter function
2424
*/
25-
template <typename TRet> Thread::Thread(TRet (*pFunc)()) {
25+
template <typename TRet> StdThread::StdThread(TRet (*pFunc)()) {
2626
K_ASSERT_PTR(pFunc);
2727

2828
SetFunction(pFunc);
@@ -36,7 +36,7 @@ template <typename TRet> Thread::Thread(TRet (*pFunc)()) {
3636
* @param pArg Function argument
3737
*/
3838
template <typename TRet>
39-
Thread::Thread(TRet (*pFunc)(Thread::Param), Thread::Param pArg) {
39+
StdThread::StdThread(TRet (*pFunc)(StdThread::Param), StdThread::Param pArg) {
4040
K_ASSERT_PTR(pFunc);
4141

4242
SetFunction(pFunc);
@@ -56,7 +56,7 @@ Thread::Thread(TRet (*pFunc)(Thread::Param), Thread::Param pArg) {
5656
* @param rObj Class instance
5757
*/
5858
template <typename TRet, typename TClass>
59-
Thread::Thread(TRet (TClass::*pFunc)(), TClass& rObj) {
59+
StdThread::StdThread(TRet (TClass::*pFunc)(), TClass& rObj) {
6060
K_ASSERT(pFunc);
6161

6262
SetMemberFunction(pFunc, rObj);
@@ -71,8 +71,8 @@ Thread::Thread(TRet (TClass::*pFunc)(), TClass& rObj) {
7171
* @param pArg Function argument
7272
*/
7373
template <typename TRet, typename TClass>
74-
Thread::Thread(TRet (TClass::*pFunc)(Thread::Param), TClass& rObj,
75-
Thread::Param pArg) {
74+
StdThread::StdThread(TRet (TClass::*pFunc)(StdThread::Param), TClass& rObj,
75+
StdThread::Param pArg) {
7676
K_ASSERT(pFunc);
7777

7878
SetMemberFunction(pFunc, rObj);
@@ -92,7 +92,7 @@ Thread::Thread(TRet (TClass::*pFunc)(Thread::Param), TClass& rObj,
9292
* @param rObj Class instance
9393
*/
9494
template <typename TRet, typename TClass>
95-
Thread::Thread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
95+
StdThread::StdThread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
9696
K_ASSERT(pFunc);
9797

9898
SetMemberFunction(pFunc, rObj);
@@ -107,8 +107,8 @@ Thread::Thread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
107107
* @param pArg Function argument
108108
*/
109109
template <typename TRet, typename TClass>
110-
Thread::Thread(TRet (TClass::*pFunc)(Thread::Param) const, const TClass& rObj,
111-
Thread::Param pArg) {
110+
StdThread::StdThread(TRet (TClass::*pFunc)(StdThread::Param) const,
111+
const TClass& rObj, StdThread::Param pArg) {
112112
K_ASSERT(pFunc);
113113

114114
SetMemberFunction(pFunc, rObj);
@@ -139,8 +139,8 @@ struct MemberFunction {
139139
* @param rObj Class instance
140140
*/
141141
template <typename TFunc, typename TClass>
142-
K_DONT_INLINE void ThreadImpl::SetMemberFunction(TFunc pFunc,
143-
const TClass& rObj) {
142+
K_DONT_INLINE void StdThreadImpl::SetMemberFunction(TFunc pFunc,
143+
const TClass& rObj) {
144144

145145
K_STATIC_ASSERT_EX(sizeof(TFunc) == sizeof(MemberFunction),
146146
"Not a member function");

lib/libkiwi/hostio/kiwiHostIOServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Server::Server()
1616
mpServerSocket(nullptr),
1717
mpClientSocket(nullptr) {
1818

19-
mpMainThread = new Thread(ThreadFunc, *this);
19+
mpMainThread = new StdThread(ThreadFunc, *this);
2020
K_ASSERT_PTR(mpMainThread);
2121
}
2222

lib/libkiwi/hostio/kiwiHostIOServer.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifndef LIBKIWI_HOSTIO_HOST_IO_SERVER_H
22
#define LIBKIWI_HOSTIO_HOST_IO_SERVER_H
3-
#include <libkiwi/core/kiwiThread.h>
43
#include <libkiwi/hostio/kiwiHostIOContext.h>
54
#include <libkiwi/k_types.h>
65
#include <libkiwi/net/kiwiSyncSocket.h>
@@ -12,6 +11,10 @@
1211
namespace kiwi {
1312
//! @addtogroup libkiwi_hostio
1413
//! @{
14+
15+
// Forward declarations
16+
class StdThread;
17+
1518
namespace hostio {
1619
//! @addtogroup libkiwi_hostio
1720
//! @{
@@ -89,7 +92,7 @@ class Server : public DynamicSingleton<Server> {
8992
Reflexible* mpRootNode;
9093

9194
//! Main loop thread
92-
Thread* mpMainThread;
95+
StdThread* mpMainThread;
9396

9497
//! Server socket
9598
SyncSocket* mpServerSocket;

lib/libkiwi/libkiwi.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <libkiwi/core/kiwiSceneCreator.h>
1919
#include <libkiwi/core/kiwiSceneHookMgr.h>
2020
#include <libkiwi/core/kiwiStaticMem.h>
21-
#include <libkiwi/core/kiwiThread.h>
21+
#include <libkiwi/core/kiwiStdThread.h>
2222
#include <libkiwi/crypt/kiwiBase64.h>
2323
#include <libkiwi/crypt/kiwiChecksum.h>
2424
#include <libkiwi/crypt/kiwiSHA1.h>
@@ -53,19 +53,21 @@
5353
#include <libkiwi/net/kiwiAsyncSocket.h>
5454
#include <libkiwi/net/kiwiAsyncSocketMgr.h>
5555
#include <libkiwi/net/kiwiHttpRequest.h>
56-
#include <libkiwi/net/kiwiIPacketFactory.h>
5756
#include <libkiwi/net/kiwiNetBuffer.h>
5857
#include <libkiwi/net/kiwiNetClient.h>
5958
#include <libkiwi/net/kiwiNetConnection.h>
6059
#include <libkiwi/net/kiwiNetConnectionMgr.h>
6160
#include <libkiwi/net/kiwiNetServer.h>
62-
#include <libkiwi/net/kiwiPacketBase.h>
63-
#include <libkiwi/net/kiwiPacketFactory.h>
6461
#include <libkiwi/net/kiwiPortRegistry.h>
65-
#include <libkiwi/net/kiwiRawPacket.h>
66-
#include <libkiwi/net/kiwiSizedPacket.h>
6762
#include <libkiwi/net/kiwiSocketBase.h>
6863
#include <libkiwi/net/kiwiSyncSocket.h>
64+
#include <libkiwi/net/packet/kiwiFixedPacket.h>
65+
#include <libkiwi/net/packet/kiwiFixedPacketFactory.h>
66+
#include <libkiwi/net/packet/kiwiIPacketFactory.h>
67+
#include <libkiwi/net/packet/kiwiPacketBase.h>
68+
#include <libkiwi/net/packet/kiwiPacketFactory.h>
69+
#include <libkiwi/net/packet/kiwiVariablePacket.h>
70+
#include <libkiwi/net/packet/kiwiVariablePacketFactory.h>
6971
#include <libkiwi/prim/kiwiAlgorithm.h>
7072
#include <libkiwi/prim/kiwiArray.h>
7173
#include <libkiwi/prim/kiwiBitCast.h>

lib/libkiwi/net/kiwiAsyncSocket.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class AsyncSocket::RecvJob : public IJob {
229229
pAsyncSocket->mType);
230230
K_ASSERT_PTR(mpSocket);
231231

232-
mpPacket = new RawPacket();
232+
mpPacket = new FixedPacket();
233233
mpPacket->Alloc(len);
234234
mpPacket->Recv(mpSocket);
235235
}
@@ -275,7 +275,7 @@ class AsyncSocket::RecvJob : public IJob {
275275
//! Temporary socket for synchronous communication
276276
SyncSocket* mpSocket;
277277
//! Raw data packet
278-
RawPacket* mpPacket;
278+
FixedPacket* mpPacket;
279279

280280
//! Destination buffer
281281
void* mpDst;
@@ -327,7 +327,7 @@ class AsyncSocket::SendJob : public IJob {
327327
pAsyncSocket->mType);
328328
K_ASSERT_PTR(mpSocket);
329329

330-
mpPacket = new RawPacket(pPeerAddr);
330+
mpPacket = new FixedPacket(pPeerAddr);
331331
mpPacket->Alloc(len);
332332
mpPacket->SetContent(pSrc, len);
333333
mpPacket->Send(mpSocket);
@@ -367,7 +367,7 @@ class AsyncSocket::SendJob : public IJob {
367367
//! Temporary socket for synchronous communication
368368
SyncSocket* mpSocket;
369369
//! Raw data packet
370-
RawPacket* mpPacket;
370+
FixedPacket* mpPacket;
371371

372372
//! Transfer callback
373373
XferCallback mpCallback;

lib/libkiwi/net/kiwiAsyncSocketMgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace detail {
77
* @brief Constructor
88
*/
99
AsyncSocketMgr::AsyncSocketMgr() {
10-
mpThread = new Thread(&AsyncSocketMgr::ThreadFunc, *this);
10+
mpThread = new StdThread(&AsyncSocketMgr::ThreadFunc, *this);
1111
}
1212

1313
/**

0 commit comments

Comments
 (0)