Compare commits
2 Commits
master
...
fb-emscrip
Author | SHA1 | Date |
---|---|---|
keldu | 1acf4380c8 | |
Claudius Holeksa | 27b737cf26 |
|
@ -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"))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include "driver/io-wasm.h"
|
||||
|
||||
namespace gin {
|
||||
namespace wasm {
|
||||
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue