Add docker file

This commit is contained in:
2025-01-08 08:41:41 -06:00
parent 5cd54469de
commit 23bf0d94e9
14 changed files with 226 additions and 44 deletions

View File

@ -117,7 +117,7 @@ namespace Tesses::Framework::Filesystem
VFSPath LocalFilesystem::SystemToVFSPath(std::string path)
{
VFSPath p;
p.path = VFSPath::SplitPath(path,true);
p.path = VFSPath::SplitPath(path);
p.relative=true;
if(!path.empty())
{

View File

@ -153,6 +153,39 @@ namespace Tesses::Framework::Filesystem
{
return VFSPath(p) + p2;
}
bool operator==(VFSPath p,VFSPath p2)
{
if(p.relative != p2.relative) return false;
if(p.path.size() != p2.path.size()) return false;
for(size_t i = 0; i < p.path.size(); i++)
if(p.path[i] != p2.path[i]) return false;
return true;
}
bool operator!=(VFSPath p,VFSPath p2)
{
if(p.relative != p2.relative) return true;
if(p.path.size() != p2.path.size()) return true;
for(size_t i = 0; i < p.path.size(); i++)
if(p.path[i] != p2.path[i]) return true;
return false;
}
bool operator==(std::string p,VFSPath p2)
{
return VFSPath(p) == p2;
}
bool operator!=(std::string p,VFSPath p2)
{
return VFSPath(p) != p2;
}
bool operator==(VFSPath p,std::string p2)
{
return p == VFSPath(p2);
}
bool operator!=(VFSPath p,std::string p2)
{
return p != VFSPath(p2);
}
VFSPath VFS::ReadLink(VFSPath path)
{
return VFSPath("/");
@ -191,7 +224,7 @@ namespace Tesses::Framework::Filesystem
return path;
}
std::vector<std::string> VFSPath::SplitPath(std::string path,bool nativePath)
std::vector<std::string> VFSPath::SplitPath(std::string path)
{
std::vector<std::string> parts;
std::string curPath = {};
@ -206,7 +239,7 @@ namespace Tesses::Framework::Filesystem
}
}
#if defined(WIN32)
else if(c == '\\' && nativePath)
else if(c == '\\')
{
if(!curPath.empty())
{
@ -236,6 +269,47 @@ namespace Tesses::Framework::Filesystem
{
this->path = p;
}
bool VFSPath::HasExtension()
{
if(this->path.empty()) return false;
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index == std::string::npos) return false;
return true;
}
std::string VFSPath::GetExtension()
{
if(this->path.empty()) return {};
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index == std::string::npos) return {};
return str.substr(index);
}
void VFSPath::ChangeExtension(std::string ext)
{
if(this->path.empty()) return;
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index != std::string::npos)
{
str = str.substr(0,index);
}
if(ext.empty()) return;
if(ext[0] != '.')
{
str += '.' + ext;
}
else
{
str += ext;
}
}
void VFSPath::RemoveExtension()
{
ChangeExtension({});
}
VFSPath::VFSPath(std::string str)
{
this->path = SplitPath(str);
@ -247,7 +321,7 @@ namespace Tesses::Framework::Filesystem
{
auto firstPartPath = this->path.front();
if(!firstPartPath.empty() && firstPartPath.back() == '/') this->relative=false;
if(!firstPartPath.empty() && firstPartPath.back() == ':') this->relative=false;
}
}
}
@ -265,6 +339,8 @@ namespace Tesses::Framework::Filesystem
{
std::vector<std::string> paths;
if(this->path.empty()) return VFSPath();
if(!this->relative && this->path.size() == 1 && !this->path[0].empty() && this->path[0].back() == ':') return *this;
paths.insert(paths.begin(), this->path.begin(), this->path.end()-1);
auto res= VFSPath(paths);
res.relative = this->relative;
@ -280,6 +356,7 @@ namespace Tesses::Framework::Filesystem
std::string VFSPath::ToString()
{
if(this->path.empty() && !this->relative) return "/";
if(!this->relative && this->path.size() == 1 && !this->path[0].empty() && this->path[0].back() == ':') return this->path[0] + "/";
bool first=true;
std::string p = {};
for(auto item : this->path)

View File

@ -94,6 +94,31 @@ namespace Tesses::Framework::Http
{
if(this->queryParams.kvp.empty()) return this->originalPath;
return this->originalPath + "?" + HttpUtils::QueryParamsEncode(this->queryParams);
}
void ServerContext::ReadStream(Stream* strm)
{
if(strm == nullptr) return;
auto strm2 = this->OpenRequestStream();
if(strm2 != nullptr)
{
strm2->CopyTo(strm);
delete strm2;
}
}
void ServerContext::ReadStream(Stream& strm)
{
ReadStream(&strm);
}
std::string ServerContext::ReadString()
{
if(strm == nullptr) return {};
auto strm2 = this->OpenRequestStream();
if(strm2 != nullptr)
{
TextStreams::StreamReader reader(strm2,true);
return reader.ReadToEnd();
}
return {};
}
bool ServerContext::NeedToParseFormData()
{
@ -628,7 +653,7 @@ namespace Tesses::Framework::Http
uint8_t* buffer = new uint8_t[len];
len = bStrm.ReadBlock(buffer,len);
std::string query((const char*)buffer,len);
delete buffer;
delete[] buffer;
HttpUtils::QueryParamsDecode(ctx.queryParams, query);
}
@ -658,4 +683,4 @@ namespace Tesses::Framework::Http
if(bStrm.EndOfStream()) return;
}
}
}
}

View File

@ -32,7 +32,7 @@ extern "C" {
#if defined(GEKKO)
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
#elif !defined(_WIN32)
#elif !defined(_WIN32) && !defined(__ANDROID__)
#include <ifaddrs.h>
#endif
@ -71,7 +71,7 @@ namespace Tesses::Framework::Streams {
char gateway[16];
if_config(localIp,netmask, gateway, true, 1);
ipConfig.push_back(std::pair<std::string,std::string>("net",localIp));
#elif defined(_WIN32)
#elif defined(_WIN32) || defined(__ANDROID__)
#else
struct ifaddrs *ifAddrStruct = NULL;
@ -503,7 +503,10 @@ namespace Tesses::Framework::Streams {
if(!this->success) return 0;
ssize_t sz2 = NETWORK_SEND(this->sock,(const char*)buff,sz, 0);
if(sz2 < 0) return 0;
if(sz2 <= 0) {
this->endOfStream=true;
return 0;
}
return (size_t)sz;
}
@ -550,4 +553,4 @@ namespace Tesses::Framework::Streams {
if(this->owns && this->success)
NETWORK_CLOSE(this->sock);
}
}
}

View File

@ -1,5 +1,6 @@
#include "TessesFramework/Threading/Mutex.hpp"
#include <cstring>
#include <iostream>
namespace Tesses::Framework::Threading
{
Mutex::Mutex()
@ -10,9 +11,10 @@ namespace Tesses::Framework::Threading
mtx = LWP_MUTEX_NULL;
LWP_MutexInit(&mtx, true);
#else
memset(&mtx, 0, sizeof(mtx_t));
mtx_init(&mtx, mtx_recursive);
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mtx,&attr);
#endif
}
void Mutex::Lock()
@ -22,7 +24,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexLock(mtx);
#else
mtx_lock(&mtx);
pthread_mutex_lock(&mtx);
#endif
}
void Mutex::Unlock()
@ -32,7 +34,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexUnlock(mtx);
#else
mtx_unlock(&mtx);
pthread_mutex_unlock(&mtx);
#endif
}
bool Mutex::TryLock()
@ -42,7 +44,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
return LWP_MutexTryLock(mtx) == 0;
#else
return mtx_trylock(&mtx) == thrd_success;
return pthread_mutex_trylock(&mtx) == 0;
#endif
}
Mutex::~Mutex()
@ -52,8 +54,9 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexDestroy(mtx);
#else
mtx_destroy(&mtx);
pthread_mutex_destroy(&mtx);
pthread_mutexattr_destroy(&attr);
#endif
}
};
};

View File

@ -18,22 +18,17 @@ namespace Tesses::Framework::Threading
}
#else
#if defined(GEKKO)
void* Thread::cb(void* data)
#else
int Thread::cb(void* data)
#endif
{
{
auto thrd = static_cast<Thread*>(data);
auto fn = thrd->fn;
thrd->hasInvoked=true;
fn();
#if defined(GEKKO)
return NULL;
#else
return 0;
#endif
}
#endif
Thread::Thread(std::function<void()> fn)
@ -43,10 +38,10 @@ namespace Tesses::Framework::Threading
#if defined(_WIN32)
this->thrd = CreateThread(NULL,0,cb,static_cast<LPVOID>(this), 0, &this->thrdId);
#elif defined(GEKKO)
thrd = LWP_THREAD_NULL;
LWP_CreateThread(&thrd, cb, static_cast<void*>(this), NULL, 12000, LWP_PRIO_HIGHEST);
auto res = LWP_CreateThread(&this->thrd, cb, static_cast<void*>(this), nullptr,12000, 98);
#else
thrd_create(&thrd, cb, static_cast<void*>(this));
pthread_create(&thrd,NULL,cb,static_cast<void*>(this));
//thrd_create(&thrd, cb, static_cast<void*>(this));
#endif
while(!this->hasInvoked);
}
@ -56,7 +51,7 @@ namespace Tesses::Framework::Threading
#if defined(_WIN32)
CloseHandle(thrd);
#else
thrd_detach(thrd);
pthread_detach(thrd);
#endif
#endif
}
@ -69,9 +64,8 @@ namespace Tesses::Framework::Threading
void* res;
LWP_JoinThread(thrd,&res);
#else
int res;
thrd_join(thrd,&res);
pthread_join(thrd,NULL);
#endif
}
}
}