mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
commit
d158ab0ff0
|
@ -1,4 +1,5 @@
|
|||
import os, imp, sys
|
||||
import os
|
||||
import sys
|
||||
from datatypes import *
|
||||
import content
|
||||
import network
|
||||
|
|
|
@ -60,7 +60,6 @@ static DBG_LOGGER loggers[16];
|
|||
static int num_loggers = 0;
|
||||
|
||||
static NETSTATS network_stats = {0};
|
||||
static MEMSTATS memory_stats = {0};
|
||||
|
||||
static NETSOCKET invalid_socket = {NETTYPE_INVALID, -1, -1};
|
||||
|
||||
|
@ -260,80 +259,14 @@ static const int MEM_GUARD_VAL = 0xbaadc0de;
|
|||
|
||||
void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment)
|
||||
{
|
||||
/* TODO: fix alignment */
|
||||
/* TODO: add debugging */
|
||||
MEMTAIL *tail;
|
||||
MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL));
|
||||
dbg_assert(header != 0, "mem_alloc failure");
|
||||
if(!header)
|
||||
return NULL;
|
||||
tail = (struct MEMTAIL *)(((char*)(header+1))+size);
|
||||
header->size = size;
|
||||
header->filename = filename;
|
||||
header->line = line;
|
||||
|
||||
memory_stats.allocated += header->size;
|
||||
memory_stats.total_allocations++;
|
||||
memory_stats.active_allocations++;
|
||||
|
||||
tail->guard = MEM_GUARD_VAL;
|
||||
|
||||
header->prev = (MEMHEADER *)0;
|
||||
header->next = first;
|
||||
if(first)
|
||||
first->prev = header;
|
||||
first = header;
|
||||
|
||||
/*dbg_msg("mem", "++ %p", header+1); */
|
||||
return header+1;
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void mem_free(void *p)
|
||||
{
|
||||
if(p)
|
||||
{
|
||||
MEMHEADER *header = (MEMHEADER *)p - 1;
|
||||
MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size);
|
||||
|
||||
if(tail->guard != MEM_GUARD_VAL)
|
||||
dbg_msg("mem", "!! %p", p);
|
||||
/* dbg_msg("mem", "-- %p", p); */
|
||||
memory_stats.allocated -= header->size;
|
||||
memory_stats.active_allocations--;
|
||||
|
||||
if(header->prev)
|
||||
header->prev->next = header->next;
|
||||
else
|
||||
first = header->next;
|
||||
if(header->next)
|
||||
header->next->prev = header->prev;
|
||||
|
||||
free(header);
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
void mem_debug_dump(IOHANDLE file)
|
||||
{
|
||||
char buf[1024];
|
||||
MEMHEADER *header = first;
|
||||
if(!file)
|
||||
file = io_open("memory.txt", IOFLAG_WRITE);
|
||||
|
||||
if(file)
|
||||
{
|
||||
while(header)
|
||||
{
|
||||
str_format(buf, sizeof(buf), "%s(%d): %d", header->filename, header->line, header->size);
|
||||
io_write(file, buf, strlen(buf));
|
||||
io_write_newline(file);
|
||||
header = header->next;
|
||||
}
|
||||
|
||||
io_close(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mem_copy(void *dest, const void *source, unsigned size)
|
||||
{
|
||||
memcpy(dest, source, size);
|
||||
|
@ -469,14 +402,44 @@ int io_flush(IOHANDLE io)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct THREAD_RUN
|
||||
{
|
||||
void (*threadfunc)(void *);
|
||||
void *u;
|
||||
};
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
static void *thread_run(void *user)
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
static unsigned long __stdcall thread_run(void *user)
|
||||
#else
|
||||
#error not implemented
|
||||
#endif
|
||||
{
|
||||
struct THREAD_RUN *data = user;
|
||||
void (*threadfunc)(void *) = data->threadfunc;
|
||||
void *u = data->u;
|
||||
free(data);
|
||||
threadfunc(u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *thread_init(void (*threadfunc)(void *), void *u)
|
||||
{
|
||||
struct THREAD_RUN *data = malloc(sizeof(*data));
|
||||
data->threadfunc = threadfunc;
|
||||
data->u = u;
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
pthread_t id;
|
||||
pthread_create(&id, NULL, (void *(*)(void*))threadfunc, u);
|
||||
return (void*)id;
|
||||
{
|
||||
pthread_t id;
|
||||
if(pthread_create(&id, NULL, thread_run, data) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (void*)id;
|
||||
}
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc, u, 0, NULL);
|
||||
return CreateThread(NULL, 0, thread_run, data, 0, NULL);
|
||||
#else
|
||||
#error not implemented
|
||||
#endif
|
||||
|
@ -1993,11 +1956,6 @@ int mem_comp(const void *a, const void *b, int size)
|
|||
return memcmp(a,b,size);
|
||||
}
|
||||
|
||||
const MEMSTATS *mem_stats()
|
||||
{
|
||||
return &memory_stats;
|
||||
}
|
||||
|
||||
void net_stats(NETSTATS *stats_inout)
|
||||
{
|
||||
*stats_inout = network_stats;
|
||||
|
@ -2216,7 +2174,7 @@ int secure_random_init()
|
|||
return 0;
|
||||
}
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
if(CryptAcquireContext(&secure_random_data.provider, NULL, NULL, PROV_RSA_FULL, 0))
|
||||
if(CryptAcquireContext(&secure_random_data.provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
|
||||
{
|
||||
secure_random_data.initialized = 1;
|
||||
return 0;
|
||||
|
|
|
@ -170,14 +170,6 @@ void mem_zero(void *block, unsigned size);
|
|||
*/
|
||||
int mem_comp(const void *a, const void *b, int size);
|
||||
|
||||
/*
|
||||
Function: mem_check
|
||||
Validates the heap
|
||||
Will trigger a assert if memory has failed.
|
||||
*/
|
||||
int mem_check_imp();
|
||||
#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed")
|
||||
|
||||
/* Group: File IO */
|
||||
enum {
|
||||
IOFLAG_READ = 1,
|
||||
|
@ -1203,8 +1195,6 @@ int net_would_block();
|
|||
|
||||
int net_socket_read_wait(NETSOCKET sock, int time);
|
||||
|
||||
void mem_debug_dump(IOHANDLE file);
|
||||
|
||||
void swap_endian(void *data, unsigned elem_size, unsigned num);
|
||||
|
||||
|
||||
|
@ -1215,15 +1205,6 @@ void dbg_logger_stdout();
|
|||
void dbg_logger_debugger();
|
||||
void dbg_logger_file(const char *filename);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int allocated;
|
||||
int active_allocations;
|
||||
int total_allocations;
|
||||
} MEMSTATS;
|
||||
|
||||
const MEMSTATS *mem_stats();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sent_packets;
|
||||
|
|
|
@ -672,10 +672,8 @@ void CClient::DebugRender()
|
|||
total = 42
|
||||
*/
|
||||
FrameTimeAvg = FrameTimeAvg*0.9f + m_RenderFrameTime*0.1f;
|
||||
str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d",
|
||||
str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d gfxmem: %dk fps: %3d",
|
||||
m_CurGameTick, m_PredTick,
|
||||
mem_stats()->allocated/1024,
|
||||
mem_stats()->total_allocations,
|
||||
Graphics()->MemoryUsage()/1024,
|
||||
(int)(1.0f/FrameTimeAvg + 0.5f));
|
||||
Graphics()->QuadsText(2, 2, 16, aBuffer);
|
||||
|
|
|
@ -1290,12 +1290,6 @@ int CServer::Run()
|
|||
m_Lastheartbeat = 0;
|
||||
m_GameStartTime = time_get();
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "baseline memory usage %dk", mem_stats()->allocated/1024);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf);
|
||||
}
|
||||
|
||||
while(m_RunServer)
|
||||
{
|
||||
int64 t = time_get();
|
||||
|
|
|
@ -24,16 +24,6 @@ public:
|
|||
IStorage *m_pStorage;
|
||||
bool m_Logging;
|
||||
|
||||
static void Con_DbgDumpmem(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CEngine *pEngine = static_cast<CEngine *>(pUserData);
|
||||
char aBuf[32];
|
||||
str_timestamp(aBuf, sizeof(aBuf));
|
||||
char aFilename[128];
|
||||
str_format(aFilename, sizeof(aFilename), "dumps/memory_%s.txt", aBuf);
|
||||
mem_debug_dump(pEngine->m_pStorage->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE));
|
||||
}
|
||||
|
||||
static void Con_DbgLognetwork(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CEngine *pEngine = static_cast<CEngine *>(pUserData);
|
||||
|
@ -89,7 +79,6 @@ public:
|
|||
if(!m_pConsole || !m_pStorage)
|
||||
return;
|
||||
|
||||
m_pConsole->Register("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_DbgDumpmem, this, "Dump the memory");
|
||||
m_pConsole->Register("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_DbgLognetwork, this, "Log the network");
|
||||
}
|
||||
|
||||
|
|
|
@ -608,3 +608,7 @@ void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser)
|
|||
str_format(aBuf, sizeof(aBuf), "saved banlist to '%s'", pFilename);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf);
|
||||
}
|
||||
|
||||
// explicitly instantiate template for src/engine/server/server.cpp
|
||||
template void CNetBan::MakeBanInfo<CNetRange>(const CBan<CNetRange> *pBan, char *pBuf, unsigned BufferSize, int Type) const;
|
||||
template void CNetBan::MakeBanInfo<NETADDR>(const CBan<NETADDR> *pBan, char *pBuf, unsigned BufferSize, int Type) const;
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
CURRENT:
|
||||
packet header: 7 bytes (9 bytes for connless)
|
||||
unsigned char flags_ack; // 6bit flags, 2bit ack
|
||||
unsigned char ack; // 8bit ack
|
||||
unsigned char numchunks; // 8bit chunks
|
||||
unsigned char token[4]; // 32bit token
|
||||
unsigned char flags_ack; // 6bit flags, 2bit ack
|
||||
unsigned char ack; // 8bit ack
|
||||
unsigned char numchunks; // 8bit chunks
|
||||
unsigned char token[4]; // 32bit token
|
||||
// ffffffaa
|
||||
// aaaaaaaa
|
||||
// NNNNNNNN
|
||||
|
|
Loading…
Reference in a new issue