Skip to content

Commit d04ba85

Browse files
committed
repo: update from holylib
1 parent 75180a5 commit d04ba85

File tree

6 files changed

+107
-116
lines changed

6 files changed

+107
-116
lines changed

source/httpserver.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
#include "baseclient.h"
55
#include "inetchannel.h"
66

7-
void CallFunc(int func, RequestData* request, ResponseData* response)
7+
void CallFunc(int func, HttpRequest* request, HttpResponse* response)
88
{
99
g_Lua->ReferencePush(func);
1010

11-
Push_RequestData(request);
12-
Push_ResponseData(response);
11+
Push_HttpRequest(request);
12+
Push_HttpResponse(response);
1313

1414
g_Lua->PCall(2, 0, 0);
1515

16-
Delete_RequestData(request);
17-
Delete_ResponseData(response); // Destroys the Lua reference after we used it
16+
Delete_HttpRequest(request);
17+
Delete_HttpResponse(response); // Destroys the Lua reference after we used it
1818
}
1919

2020
void HttpServer::Start(const char* address, unsigned port)
@@ -52,7 +52,7 @@ void HttpServer::Think()
5252
continue;
5353
}
5454

55-
CallFunc(pEntry->iFunction, pEntry, pEntry->pResponseData);
55+
CallFunc(pEntry->iFunction, pEntry, &pEntry->pResponseData);
5656
pEntry->bHandled = true;
5757
}
5858

@@ -82,18 +82,17 @@ httplib::Server::Handler HttpServer::CreateHandler(const char* path, int func, b
8282
if (!found) { return; }
8383
}
8484

85-
RequestData* request = new RequestData;
85+
HttpRequest* request = new HttpRequest;
8686
request->strPath = path;
8787
request->pRequest = req;
8888
request->iFunction = func;
8989
request->pResponse = res;
90-
request->pResponseData = new ResponseData;
9190
m_pRequests.push_back(request); // We should add a check here since we could write to it from multiple threads?
9291
m_bUpdate = true;
9392
while (!request->bHandled) {
9493
ThreadSleep(1);
9594
}
96-
ResponseData* rdata = request->pResponseData;
95+
HttpResponse* rdata = &request->pResponseData;
9796
if (rdata->bSetContent) {
9897
res.set_content(rdata->strContent, rdata->strContentType);
9998
}

source/httpserver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "unordered_map"
33
#include "httplib.h"
44

5-
struct ResponseData {
5+
struct HttpResponse {
66
bool bSetContent = false;
77
bool bSetRedirect = false;
88
bool bSetHeader = false;
@@ -13,12 +13,12 @@ struct ResponseData {
1313
std::unordered_map<std::string, std::string> pHeaders;
1414
};
1515

16-
struct RequestData {
16+
struct HttpRequest {
1717
bool bHandled = false;
1818
bool bDelete = false;
1919
int iFunction;
2020
std::string strPath;
21-
ResponseData* pResponseData;
21+
HttpResponse pResponseData;
2222
httplib::Response pResponse;
2323
httplib::Request pRequest;
2424
};
@@ -92,6 +92,6 @@ class HttpServer
9292
bool m_bUpdate = false;
9393
bool m_bInUpdate = false;
9494
std::string m_strAddress;
95-
std::vector<RequestData*> m_pRequests;
95+
std::vector<HttpRequest*> m_pRequests;
9696
httplib::Server m_pServer;
9797
};

source/lua.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,36 +164,36 @@ LUA_FUNCTION_STATIC(HttpServer_SetTCPnodelay)
164164
LUA_FUNCTION_STATIC(HttpServer_SetReadTimeout)
165165
{
166166
HttpServer* pServer = Get_HttpServer(1, true);
167-
pServer->GetServer().set_read_timeout(LUA->CheckNumber(2), LUA->CheckNumber(3));
167+
pServer->GetServer().set_read_timeout((time_t)LUA->CheckNumber(2), (time_t)LUA->CheckNumber(3));
168168
return 0;
169169
}
170170

171171
LUA_FUNCTION_STATIC(HttpServer_SetWriteTimeout)
172172
{
173173
HttpServer* pServer = Get_HttpServer(1, true);
174-
pServer->GetServer().set_write_timeout(LUA->CheckNumber(1), LUA->CheckNumber(2));
174+
pServer->GetServer().set_write_timeout((time_t)LUA->CheckNumber(1), (time_t)LUA->CheckNumber(2));
175175
return 0;
176176
}
177177

178178
LUA_FUNCTION_STATIC(HttpServer_SetPayloadMaxLength)
179179
{
180180
HttpServer* pServer = Get_HttpServer(1, true);
181-
pServer->GetServer().set_payload_max_length(LUA->CheckNumber(2));
181+
pServer->GetServer().set_payload_max_length((size_t)LUA->CheckNumber(2));
182182
return 0;
183183
}
184184

185185
LUA_FUNCTION_STATIC(HttpServer_SetKeepAliveTimeout)
186186
{
187187
HttpServer* pServer = Get_HttpServer(1, true);
188-
pServer->GetServer().set_keep_alive_timeout(LUA->CheckNumber(2));
188+
pServer->GetServer().set_keep_alive_timeout((time_t)LUA->CheckNumber(2));
189189

190190
return 0;
191191
}
192192

193193
LUA_FUNCTION_STATIC(HttpServer_SetKeepAliveMaxCount)
194194
{
195195
HttpServer* pServer = Get_HttpServer(1, true);
196-
pServer->GetServer().set_keep_alive_max_count(LUA->CheckNumber(2));
196+
pServer->GetServer().set_keep_alive_max_count((size_t)LUA->CheckNumber(2));
197197

198198
return 0;
199199
}
@@ -218,7 +218,7 @@ LUA_FUNCTION_STATIC(HttpServer_Start)
218218
{
219219
HttpServer* pServer = Get_HttpServer(1, true);
220220
const char* address = LUA->CheckString(2);
221-
unsigned port = LUA->CheckNumber(3);
221+
unsigned int port = (unsigned int)LUA->CheckNumber(3);
222222

223223
pServer->Start(address, port);
224224

@@ -254,7 +254,7 @@ LUA_FUNCTION_STATIC(httpserver_Destroy)
254254

255255
void LUA_InitServer(GarrysMod::Lua::ILuaBase* LUA)
256256
{
257-
RequestData_LuaInit();
257+
HttpRequest_LuaInit();
258258

259259
HttpServer_TypeID = g_Lua->CreateMetaTable("HttpServer");
260260
Util::AddFunc(HttpServer__tostring, "__tostring");

source/main.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ GMOD_MODULE_OPEN()
1010
if (Util::server == nullptr)
1111
LUA->ThrowError("Failed to get IServer");
1212

13-
Gmod_Server = InterfacePointers::Server();
14-
if (Gmod_Server == nullptr)
15-
ThrowError("Failed to get IServer");
16-
17-
Engine = InterfacePointers::VEngineServer();
18-
if (Engine == nullptr)
19-
ThrowError("Failed to get IVEngineServer");
20-
2113
LUA_InitServer(LUA);
2214

2315
return 0;

0 commit comments

Comments
 (0)