WIP: Stream/Connection

This commit is contained in:
Michele Caini 2016-06-20 21:45:35 +02:00
parent a7fba77879
commit 0f8604a496
3 changed files with 35 additions and 8 deletions

View File

@ -26,7 +26,7 @@ protected:
public:
using Callback = std::function<void(UVWError)>;
virtual ~Resource() = 0;
virtual ~Resource() { static_assert(std::is_base_of<Resource<T>, T>::value, "!"); }
Resource(const Resource &) = delete;
Resource(Resource &&) = delete;
@ -51,10 +51,5 @@ private:
Callback callback;
};
template<typename T>
Resource<T>::~Resource() {
static_assert(std::is_base_of<Resource<T>, T>::value, "!");
}
}

View File

@ -7,12 +7,44 @@ namespace uvw {
template<class T>
class Connection: public Resource<T> {
using Resource<T>::Resource;
public:
// TODO read
// TODO stop
// TODO write
// TODO tryWrite
};
template<class T>
class Stream: public Connection<T> {
using Connection<T>::Connection;
static void protoListen(uv_stream_t* srv, int status) {
// TODO
}
protected:
template<typename U>
explicit Stream(U *u)
: Connection<T>{u},
handle{reinterpret_cast<uv_stream_t*>(u)}
{ }
public:
// TODO shutdown
// TODO listen
bool readable() const noexcept {
return (uv_is_readable(handle) == 1);
}
bool writable() const noexcept {
return (uv_is_writable(handle) == 1);
}
private:
uv_stream_t *handle;
};

View File

@ -33,11 +33,11 @@ public:
close([](UVWError){});
}
bool noDelay(bool value = false) {
bool noDelay(bool value = false) noexcept {
return (uv_tcp_nodelay(&handle, value ? 1 : 0) == 0);
}
bool keepAlive(bool enable = false, Time time = Time{0}) {
bool keepAlive(bool enable = false, Time time = Time{0}) noexcept {
return (uv_tcp_keepalive(&handle, enable ? 1 : 0, time.count()) == 0);
}