-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
123 lines (102 loc) · 2.75 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "commandconnection.h"
#include "gdbconnection.h"
#include "ftpconnection.h"
#include "network.h"
#include "server.h"
#include "log.h"
#include "ftp.h"
#include <vdb.h>
#include <psp2/kernel/threadmgr.h>
#include <psp2/kernel/modulemgr.h>
#include <psp2/io/fcntl.h>
namespace
{
int threadEntry(SceSize args, void *argp)
{
// wait 5 seconds for VSH to load
sceKernelDelayThread(5*1000*1000);
// setup networking
Network network;
while (1)
{
network.waitUntilConnected();
Server<GdbConnection> gdb;
Server<FtpConnection> ftp;
Server<CommandConnection> commands;
if (!gdb.listen(31337))
{
if (!network.connected())
{
LOG("network disconnected: retrying connection\n");
continue;
}
else
{
LOG("failed to listen to gdb port. aborting\n");
break;
}
}
if (!ftp.listen(1337))
{
if (!network.connected())
{
LOG("network disconnected: retrying connection\n");
continue;
}
else
{
LOG("failed to listen to ftp port. aborting\n");
break;
}
}
if (!commands.listen(1338))
{
if (!network.connected())
{
LOG("network disconnected: retrying connection\n");
continue;
}
else
{
LOG("failed to listen to command port. aborting\n");
break;
}
}
LOG("server listening\n");
while (network.connected())
{
// yield
sceKernelDelayThread(100);
}
}
return 0;
}
}
extern "C"
{
int module_start()
{
LOG("begin\n");
// tell vdb we want to use its pipes. we will transmit our data from
// tcp through these pipes
vdb_serial_pipe();
int res = sceKernelCreateThread("vdbtcp", &threadEntry, 0x40, 0x1000, 0, 0, NULL);
if (res < 0)
{
LOG("failed to create main thread: 0x%08X\n", res);
return SCE_KERNEL_START_NO_RESIDENT;
}
res = sceKernelStartThread(res, 0, NULL);
if (res < 0)
{
LOG("failed to start main thread 0x%08X\n", res);
return SCE_KERNEL_START_NO_RESIDENT;
}
return SCE_KERNEL_START_RESIDENT;
}
int module_stop()
{
return 0;
}
int _start() __attribute__ ((weak, alias ("module_start")));
}