-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·153 lines (146 loc) · 3.49 KB
/
main.cpp
File metadata and controls
executable file
·153 lines (146 loc) · 3.49 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ThreadInfo.h"
#include "cJSON.h"
#include "addone.h"
#include "etp_log/log.h"
#include "etp_sdk/modulesdk.h"
LinkLib *Linklib;
cJSON *cjsonfile;
int Port = 8001;
char LogPath[256];
cJSON *UserAgentIndexPage;
SOCKET initBindSocket(const int);
ConnectInfo conneectClient(const SOCKET);
void handClient(int sock, struct sockaddr);
void *getcommand(LPVOID);
int initserver();
extern "C"
{
ModuleType_t _init_(int proco)
{
switch (initserver())
{
case -1:
extrapidLog(LOG_ERROR, "HTTP", "初始化失败");
exit(1);
case 1:
initserver();
break;
default:
break;
}
logInit(LogPath);
ModuleType_t mod = SDK_CreateModule("HTTP module", "This is a simple http server", 1);
SDK_AddBindPort(&mod, Port, handClient);
return mod;
}
}
void *getcommand(LPVOID a)
{
char cmd[256];
while (1)
{
fgets(cmd, 256, stdin);
cmd[strlen(cmd) - 1] = 0;
if (!strcmp(cmd, "stop"))
{
printf("退出服务器\n");
exit(0);
}
else if (!strcmp(cmd, "help"))
{
printf("服务器控制台帮助文档:\n");
printf("输入stop退出服务器\n输入memuse查看进程内存使用信息\n输入bash进入系统bash控制台\n输入help查看帮助\n");
}
else if (!strcmp(cmd, "listapp"))
{
printf(">>开始列出application<<\n");
LinkLib *temp = Linklib;
while (temp)
{
printf("找到addone%s\n", temp->libname);
Func *f = temp->funcslist;
while (f)
{
printf(" 存在函数:%s\n", f->funcname);
f = f->next;
}
temp = temp->next;
}
}
else if (!strcmp(cmd, "memuse"))
{
printf(">>进程内存使用信息<<\n");
int info = open("/proc/self/status", O_RDONLY);
char text[1024];
read(info, text, 1024);
// printf("%s\n",text);
//打印内存峰值
char *p = strstr(text, "VmPeak");
printf("内存使用峰值:");
for (int i = 0; p[i] != '\n' && p != NULL; i++)
{
putc(p[i], stdout);
}
putc('\n', stdout);
//打印当前内存使用量
p = strstr(text, "VmSize:");
printf("当前内存使用量:");
for (int i = 0; p[i] != '\n' && p != NULL; i++)
{
putc(p[i], stdout);
}
putc('\n', stdout);
//打印当前物理内存使用量
p = strstr(text, "VmRSS:");
printf("当前内存使用量:");
for (int i = 0; p[i] != '\n' && p != NULL; i++)
{
putc(p[i], stdout);
}
putc('\n', stdout);
close(info);
printf(">>信息打印完成<<\n");
}
else if (!strcmp(cmd, "bash"))
{
printf(">>进入bash,输入exit返回服务器控制台<<\n");
system("bash");
printf(">>返回服务器控制台<<\n");
}
else if (strstr(cmd, "addone"))
{
addone_ConsoleControl(cmd, &Linklib);
}
else if (strstr(cmd, "_app."))
{
char addonename[256];
char funcname[256];
char *p = strstr(cmd, "_app.");
(*p) = 0; //将下划线暂时改为字符串结束
strcpy(addonename, cmd);
(*p) = '_'; //改回来
// p+=5;//移动到函数名
char *t = strstr(p + 5, " ");
if (t != NULL)
{
*t = 0;
}
printf("调试:addonename:%s funcname:%s p:%s\n", addonename, funcname, p);
if (addone_RunAddoneAsCommand(Linklib, addonename, funcname, cmd) != 0)
{
printf("UNKNOWN COMMAND!\n");
}
}
else
{
printf("UNKNOWN COMMAND!\n");
}
}
}