Compare commits

...

2 Commits

Author SHA1 Message Date
keldu 1acf4380c8 wasm headers 2021-12-27 11:46:20 +01:00
Claudius Holeksa 27b737cf26 io-wasm setup 2021-12-26 00:15:31 +01:00
4 changed files with 134 additions and 6 deletions

View File

@ -11,5 +11,5 @@ dir_path = Dir('.').abspath
env.driver_sources += sorted(glob.glob(dir_path + "/tls/*.cpp"))
env.driver_sources += sorted(glob.glob(dir_path + "/*.cpp"))
env.driver_headers += sorted(glob.glob(dir_path + "/*.h"))
env.driver_sources += sorted(glob.glob(dir_path + "/*-unix.cpp"))
env.driver_headers += sorted(glob.glob(dir_path + "/*-unix.h"))

View File

@ -26,7 +26,6 @@
#include <unordered_map>
#include <vector>
#include "./io.h"
#include "kelgin/io.h"
namespace gin {
@ -127,7 +126,7 @@ private:
notifySignalListener(siginfo.ssi_signo);
}
} else if (events[i].data.u64 == 1) {
uint8_t i;
uint64_t i;
if (pipefds[0] < 0) {
continue;
}
@ -228,8 +227,7 @@ public:
}
void wake() override {
/// @todo pipe() in the beginning and write something minor into it like
/// uint8_t or sth the value itself doesn't matter
// Writes a byte into the pipe to wake epoll up
if (pipefds[1] < 0) {
return;
}

7
driver/io-wasm.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "driver/io-wasm.h"
namespace gin {
namespace wasm {
}
}

123
driver/io-wasm.h Normal file
View File

@ -0,0 +1,123 @@
#pragma once
#ifndef GIN_WASM
#error "Don't include this"
#endif
#include <unordered_map>
#include <kelgin/io.h>
namespace gin {
namespace wasm {
class WasmEventPort;
class IFdOwner {
private:
int file_descriptor;
public:
IFdOwner(int fd);
virtual ~IFdOwner() = default;
int fd() const;
virtual void notify() = 0;
};
class WasmEventPort final : public EventPort {
private:
std::unordered_map<Signal, Own<ConveyorFeeder<void>>> signal_conveyors;
std::unordered_map<int, IFdOwner*> fd_to_owner;
void pollImpl(uint32_t time){
}
public:
Conveyor<void> onSignal(Signal signal) override {
auto caf = newConveyorAndFeeder<void>();
signal_conveyors[signal] = std::move(caf.feeder);
auto node_and_storage =
Conveyor<void>::fromConveyor(std::move(caf.conveyor));
return Conveyor<void>::toConveyor(std::move(node_and_storage.first),
node_and_storage.second);
}
void poll() override {
pollImpl(0);
}
void wait() override {
pollImpl(-1);
}
void wait(const std::chrono::steady_clock::duration& duration) override {
pollImpl(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
}
void wait(const std::chrono::steady_clock::time_point& time_point) override {
auto now = std::chrono::steady_clock::now();
if(time_point <= now){
poll();
}else {
pollImpl(std::chrono::duration_cast<std::chrono::milliseconds>(time_point -now).count());
}
}
void wake() override {
/// @todo how to wakeup in emscripten?
/// Probably with pipes again?
}
void subscribe(IFdOwner& owner);
void unsubscribe(int fd);
};
/*
* Emulated TCP stream with emscripten
*/
class WasmIoStream final : public IoStream, public IFdOwner {
private:
Own<ConveyorFeeder<void>> read_ready = nullptr;
Own<ConveyorFeeder<void>> on_read_disconnect = nullptr;
Own<ConveyorFeeder<void>> write_ready = nullptr;
public:
WasmIoStream(WasmEventPort& port, int file_desc);
ErrorOr<size_t> read(void* buffer, size_t length) override;
void notify() override;
};
/*
* Socket listen fd. Accepts incoming connections
*/
class WasmServer final : public Server, public IFdOwner {
private:
};
/*
* Network class. Created for TLS abstraction
*/
class WasmNetwork final : public Network {
private:
public:
};
/*
* Provider class for all network relevant functionality
*/
class WasmIoProvider final : public IoProvider {
private:
};
}
}