mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 07:45:46 +00:00
Make streams and vfs and http shared_ptr
This commit is contained in:
@@ -9,8 +9,6 @@ int main(int argc, char** argv)
|
||||
VFSPath dest = fs.SystemToVFSPath(argv[2]);
|
||||
auto srcs = fs.OpenFile(src,"rb");
|
||||
auto dests = fs.OpenFile(dest,"wb");
|
||||
srcs->CopyTo(*dests);
|
||||
srcs->CopyTo(dests);
|
||||
|
||||
delete srcs;
|
||||
delete dests;
|
||||
}
|
||||
@@ -13,23 +13,22 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
LocalFilesystem lfs;
|
||||
|
||||
std::string root = "./root";
|
||||
std::string mountDemi = "./demi";
|
||||
std::string mountJoelSlashJim = "./joelslashjim";
|
||||
|
||||
SubdirFilesystem rootdir(&lfs,root,false);
|
||||
std::shared_ptr<SubdirFilesystem> rootdir = std::make_shared<SubdirFilesystem>(LocalFS,root);
|
||||
|
||||
SubdirFilesystem mountDemidir(&lfs,mountDemi,false);
|
||||
std::shared_ptr<SubdirFilesystem> mountDemidir = std::make_shared<SubdirFilesystem>(LocalFS,mountDemi);
|
||||
|
||||
|
||||
SubdirFilesystem mountjohnslashjim(&lfs,mountJoelSlashJim,false);
|
||||
std::shared_ptr<SubdirFilesystem> mountjohnslashjim = std::make_shared<SubdirFilesystem>(LocalFS,mountJoelSlashJim);
|
||||
|
||||
MountableFilesystem fs(&rootdir,false);
|
||||
fs.Mount(std::string("/demi"), &mountDemidir,false);
|
||||
std::shared_ptr<MountableFilesystem> fs = std::make_shared<MountableFilesystem>(rootdir);
|
||||
fs->Mount(std::string("/demi"), mountDemidir);
|
||||
|
||||
fs.Mount(std::string("/joel/jim"), &mountjohnslashjim,false);
|
||||
fs->Mount(std::string("/joel/jim"), mountjohnslashjim);
|
||||
|
||||
std::string command = argv[1];
|
||||
|
||||
@@ -39,22 +38,22 @@ int main(int argc, char** argv)
|
||||
std::string dir = "/";
|
||||
if(argc > 2) dir = argv[2];
|
||||
|
||||
for(auto item : fs.EnumeratePaths(dir))
|
||||
for(auto item : fs->EnumeratePaths(dir))
|
||||
{
|
||||
std::cout << item.GetFileName() << std::endl;
|
||||
}
|
||||
}
|
||||
else if(command == "cat")
|
||||
{
|
||||
FileStream strm(stdout, false,"wb",false);
|
||||
std::shared_ptr<FileStream> strm = std::make_shared<FileStream>(stdout, false,"wb",false);
|
||||
for(int a = 2; a < argc; a++)
|
||||
{
|
||||
std::string path = argv[a];
|
||||
auto f = fs.OpenFile(path,"rb");
|
||||
auto f = fs->OpenFile(path,"rb");
|
||||
if(f != nullptr)
|
||||
{
|
||||
f->CopyTo(strm);
|
||||
delete f;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class MyWebServer : public IHttpServer {
|
||||
std::cout << ctx.path << std::endl;
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
FileStream fs("index.html","rb");
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("index.html","rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/html")
|
||||
@@ -34,7 +34,7 @@ class MyWebServer : public IHttpServer {
|
||||
}
|
||||
else if(ctx.path == "/streaming.html")
|
||||
{
|
||||
StreamWriter writer(ctx.OpenResponseStream(),true);
|
||||
StreamWriter writer(ctx.OpenResponseStream());
|
||||
writer.WriteLine("<html>");
|
||||
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||
writer.WriteLine("<body>");
|
||||
@@ -58,7 +58,7 @@ class MyWebServer : public IHttpServer {
|
||||
else if(ctx.path == "/main.js")
|
||||
{
|
||||
|
||||
FileStream fs("main.js","rb");
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("main.js","rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/js")
|
||||
@@ -67,8 +67,8 @@ class MyWebServer : public IHttpServer {
|
||||
}
|
||||
else if(ctx.path == "/upload")
|
||||
{
|
||||
ctx.ParseFormData([](std::string mime, std::string filename, std::string name)->Tesses::Framework::Streams::Stream*{
|
||||
return new FileStream(filename,"wb");
|
||||
ctx.ParseFormData([](std::string mime, std::string filename, std::string name)->std::shared_ptr<Tesses::Framework::Streams::Stream>{
|
||||
return std::make_shared<FileStream>(filename,"wb");
|
||||
});
|
||||
}
|
||||
else if(ctx.path == "/steve")
|
||||
@@ -117,11 +117,11 @@ class MyOtherWebServer : public IHttpServer
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
MyOtherWebServer myo;
|
||||
MyWebServer mws;
|
||||
std::shared_ptr<MyOtherWebServer> myo = std::make_shared<MyOtherWebServer>();
|
||||
std::shared_ptr<MyWebServer> mws = std::make_shared<MyWebServer>();
|
||||
|
||||
MountableServer mountable(myo);
|
||||
mountable.Mount("/mymount/",mws);
|
||||
std::shared_ptr<MountableServer> mountable = std::make_shared<MountableServer>(myo);
|
||||
mountable->Mount("/mymount/",mws);
|
||||
HttpServer server(10001,mountable);
|
||||
server.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
|
||||
@@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
Tesses::Framework::TF_Init();
|
||||
HttpDictionary reqHeaders;
|
||||
WebSocketConn conn;
|
||||
std::shared_ptr<WebSocketConn> conn = std::make_shared<WebSocketConn>();
|
||||
WebSocketClient("ws://echo.websocket.org/",reqHeaders,conn);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user