mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 21:21:04 +00:00
- fix compile on clang
- implement TCP connections in Linux - fix passing of request string to a thread - implement OS stats for ARM and PPC on Linux
This commit is contained in:
parent
d2fa4d0ff9
commit
033a11a028
2 changed files with 102 additions and 38 deletions
|
@ -58,8 +58,12 @@ static int GetOSVersion()
|
|||
|
||||
#else
|
||||
|
||||
// Todo: PPC + ARM
|
||||
|
||||
// fall-through linux stuff here
|
||||
#ifdef __arm__
|
||||
return 10;
|
||||
#elif __ppc__
|
||||
return 9;
|
||||
#else
|
||||
if (sizeof(void*) == 4) // 32 bit
|
||||
{
|
||||
return 11;
|
||||
|
@ -68,6 +72,7 @@ static int GetOSVersion()
|
|||
{
|
||||
return 12;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -123,7 +128,8 @@ void D_DoAnonStats()
|
|||
if (currentrenderer == 0 && sentstats_swr) return;
|
||||
if (currentrenderer == 1 && sentstats_hwr) return;
|
||||
|
||||
FStringf requeststring("GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n",
|
||||
static char requeststring[1024];
|
||||
sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n",
|
||||
GetRenderInfo(), GetCoreInfo(), GetOSVersion(), sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR);
|
||||
DPrintf(DMSG_NOTIFY, "Sending %s", requeststring);
|
||||
std::thread t1(D_DoHTTPRequest, requeststring);
|
||||
|
|
|
@ -36,6 +36,11 @@
|
|||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "doomerrors.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -69,6 +74,8 @@
|
|||
#include "g_level.h"
|
||||
|
||||
EXTERN_CVAR (String, language)
|
||||
EXTERN_CVAR(String, sys_statshost)
|
||||
EXTERN_CVAR(Int, sys_statsport)
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -490,8 +497,59 @@ TArray<FString> I_GetGogPaths()
|
|||
return TArray<FString>();
|
||||
}
|
||||
|
||||
|
||||
bool I_HTTPRequest(const char* request)
|
||||
{
|
||||
// todo
|
||||
if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0)
|
||||
return false; // no host, disable
|
||||
|
||||
int sockfd, portno, n;
|
||||
struct sockaddr_in serv_addr;
|
||||
struct hostent *server;
|
||||
|
||||
portno = sys_statsport;
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sockfd < 0)
|
||||
{
|
||||
DPrintf(DMSG_ERROR, "Error opening TCP socket.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
server = gethostbyname(sys_statshost.GetHumanString());
|
||||
if (server == NULL)
|
||||
{
|
||||
DPrintf(DMSG_ERROR, "Error looking up hostname.\n");
|
||||
return false;
|
||||
}
|
||||
bzero((char*) &serv_addr, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
bcopy((char *)server->h_addr,
|
||||
(char *)&serv_addr.sin_addr.s_addr,
|
||||
server->h_length);
|
||||
serv_addr.sin_port = htons(portno);
|
||||
|
||||
DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString());
|
||||
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString());
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[1024];
|
||||
sprintf(buffer, "%s", request);
|
||||
Printf("Buffer: %s", buffer);
|
||||
n = write(sockfd, (char*)buffer, (int)strlen(request));
|
||||
if (n<0)
|
||||
{
|
||||
DPrintf(DMSG_ERROR, "Error writing to socket.\n");
|
||||
close(sockfd);
|
||||
return false;
|
||||
}
|
||||
bzero(buffer, 1024);
|
||||
|
||||
n = read(sockfd, buffer, 1023);
|
||||
close(sockfd);
|
||||
DPrintf(DMSG_NOTIFY, "Stats send successful.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue