Merge pull request #10 from cynnyx/master

noexcept review
This commit is contained in:
Michele Caini 2016-07-17 00:44:37 +02:00 committed by GitHub
commit a6a4af1957
10 changed files with 37 additions and 35 deletions

View File

@ -28,7 +28,7 @@ public:
return std::shared_ptr<Async>{new Async{std::forward<Args>(args)...}};
}
bool init() { return initialize<uv_async_t>(&uv_async_init, sendCallback); }
bool init() { return initialize<uv_async_t>(&uv_async_init, &sendCallback); }
void send() { invoke(&uv_async_send, get<uv_async_t>()); }
};

View File

@ -33,12 +33,12 @@ class Emitter {
return onceL.empty() && onL.empty();
}
Connection once(Listener f) noexcept {
Connection once(Listener f) {
auto conn = onceL.insert(onceL.cbegin(), std::move(f));
return { onceL, std::move(conn) };
}
Connection on(Listener f) noexcept {
Connection on(Listener f) {
auto conn = onL.insert(onL.cbegin(), std::move(f));
return { onL, std::move(conn) };
}
@ -52,7 +52,7 @@ class Emitter {
onL.clear();
}
void publish(const E &event, T &ref) noexcept {
void publish(const E &event, T &ref) {
for(auto &&listener: onceL) { listener(event, ref); }
for(auto &&listener: onL) { listener(event, ref); }
onceL.clear();
@ -82,7 +82,7 @@ class Emitter {
protected:
template<typename E>
void publish(E event) noexcept {
void publish(E event) {
handler<E>().publish(event, *static_cast<T*>(this));
}
@ -98,17 +98,17 @@ public:
template<typename E>
using Listener = typename Handler<E>::Listener;
virtual ~Emitter() {
virtual ~Emitter() noexcept {
static_assert(std::is_base_of<Emitter<T>, T>::value, "!");
}
template<typename E>
Connection<E> on(Listener<E> f) noexcept {
Connection<E> on(Listener<E> f) {
return handler<E>().on(std::move(f));
}
template<typename E>
Connection<E> once(Listener<E> f) noexcept {
Connection<E> once(Listener<E> f) {
return handler<E>().once(std::move(f));
}

View File

@ -11,7 +11,7 @@ namespace uvw {
struct BaseEvent {
virtual ~BaseEvent() = 0;
virtual ~BaseEvent() noexcept = 0;
static std::size_t next() noexcept {
static std::size_t cnt = 0;
@ -19,7 +19,7 @@ struct BaseEvent {
}
};
BaseEvent::~BaseEvent() { }
BaseEvent::~BaseEvent() noexcept { }
template<typename E>
struct Event: BaseEvent {

View File

@ -25,12 +25,14 @@ public:
class Loop final: public Emitter<Loop>, public std::enable_shared_from_this<Loop> {
using Deleter = void(*)(uv_loop_t *);
template<typename>
friend class Resource;
using Deleter = std::function<void(uv_loop_t *)>;
Loop(std::unique_ptr<uv_loop_t, Deleter> ptr): loop{std::move(ptr)} { }
Loop(std::unique_ptr<uv_loop_t, Deleter> ptr) noexcept
: loop{std::move(ptr)}
{ }
public:
static std::shared_ptr<Loop> create() {
@ -69,7 +71,7 @@ public:
Loop& operator=(const Loop &) = delete;
Loop& operator=(Loop &&other) = delete;
~Loop() {
~Loop() noexcept {
if(loop) {
close();
}
@ -89,7 +91,7 @@ public:
return R::create(shared_from_this(), std::forward<Args>(args)...);
}
void close() noexcept {
void close() {
auto err = uv_loop_close(loop.get());
if(err) { publish(ErrorEvent{err}); }
}
@ -114,7 +116,7 @@ public:
uv_stop(loop.get());
}
void walk(std::function<void(BaseHandle &)> callback) noexcept {
void walk(std::function<void(BaseHandle &)> callback) {
// remember: non-capturing lambdas decay to pointers to functions
uv_walk(loop.get(), [](uv_handle_t *handle, void *func) {
BaseHandle &ref = *static_cast<BaseHandle*>(handle->data);

View File

@ -48,7 +48,7 @@ protected:
}
public:
void cancel() noexcept {
void cancel() {
invoke(&uv_cancel, this->template get<uv_req_t>());
}

View File

@ -30,7 +30,7 @@ public:
bool init() { return initialize<uv_signal_t>(&uv_signal_init); }
void start(int signum) { invoke(uv_signal_start, get<uv_signal_t>(), &startCallback, signum); }
void start(int signum) { invoke(&uv_signal_start, get<uv_signal_t>(), &startCallback, signum); }
void stop() { invoke(&uv_signal_stop, get<uv_signal_t>()); }
int signal() const noexcept { return get<uv_signal_t>()->signum; }

View File

@ -29,7 +29,7 @@ public:
return std::shared_ptr<Shutdown>{new Shutdown{std::forward<Args>(args)...}};
}
void shutdown(uv_stream_t *handle) noexcept {
void shutdown(uv_stream_t *handle) {
exec<uv_shutdown_t, ShutdownEvent>(&uv_shutdown, get<uv_shutdown_t>(), handle);
}
};
@ -90,7 +90,7 @@ protected:
{ }
public:
void shutdown() noexcept {
void shutdown() {
std::weak_ptr<T> weak = this->shared_from_this();
auto listener = [weak](const auto &event, details::Shutdown &) {
@ -104,11 +104,11 @@ public:
shutdown->shutdown(this->template get<uv_stream_t>());
}
void listen(int backlog) noexcept {
void listen(int backlog) {
this->invoke(&uv_listen, this->template get<uv_stream_t>(), backlog, &listenCallback);
}
void listen() noexcept {
void listen() {
listen(DEFAULT_BACKLOG);
}
@ -116,7 +116,7 @@ public:
this->invoke(&uv_read_start, this->template get<uv_stream_t>(), &allocCallback, &readCallback);
}
void stop() noexcept {
void stop() {
this->invoke(&uv_read_stop, this->template get<uv_stream_t>());
}
@ -139,7 +139,7 @@ public:
write(data.get(), length);
}
int tryWrite(char *data, ssize_t length) noexcept {
int tryWrite(char *data, ssize_t length) {
uv_buf_t bufs[] = { uv_buf_init(data, length) };
auto bw = uv_try_write(this->template get<uv_stream_t>(), bufs, 1);
@ -151,7 +151,7 @@ public:
return bw;
}
int tryWrite(std::unique_ptr<char[]> data, ssize_t length) noexcept {
int tryWrite(std::unique_ptr<char[]> data, ssize_t length) {
return tryWrite(data.get(), length);
}

View File

@ -29,7 +29,7 @@ public:
return std::shared_ptr<Connect>{new Connect{std::forward<Args>(args)...}};
}
void connect(uv_tcp_t *handle, const sockaddr *addr) noexcept {
void connect(uv_tcp_t *handle, const sockaddr *addr) {
exec<uv_connect_t, ConnectEvent>(&uv_tcp_connect, get<uv_connect_t>(), handle, addr);
}
};
@ -81,16 +81,16 @@ public:
bool init() { return initialize<uv_tcp_t>(&uv_tcp_init); }
void noDelay(bool value = false) noexcept {
void noDelay(bool value = false) {
invoke(&uv_tcp_nodelay, get<uv_tcp_t>(), value ? 1 : 0);
}
void keepAlive(bool enable = false, Time time = Time{0}) noexcept {
void keepAlive(bool enable = false, Time time = Time{0}) {
invoke(&uv_tcp_keepalive, get<uv_tcp_t>(), enable ? 1 : 0, time.count());
}
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void bind(std::string ip, unsigned int port, bool ipv6only = false) noexcept {
void bind(std::string ip, unsigned int port, bool ipv6only = false) {
typename Traits::Type addr;
Traits::AddrFunc(ip.c_str(), port, &addr);
unsigned int flags = ipv6only ? UV_TCP_IPV6ONLY : 0;
@ -98,7 +98,7 @@ public:
}
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void bind(Addr addr, bool ipv6only = false) noexcept {
void bind(Addr addr, bool ipv6only = false) {
bind<I>(addr.ip, addr.port, ipv6only);
}
@ -113,7 +113,7 @@ public:
}
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void connect(std::string ip, unsigned int port) noexcept {
void connect(std::string ip, unsigned int port) {
typename Traits::Type addr;
Traits::AddrFunc(ip.c_str(), port, &addr);
@ -131,11 +131,11 @@ public:
}
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void connect(Addr addr) noexcept {
void connect(Addr addr) {
connect<I>(addr.ip, addr.port);
}
void accept(Tcp &tcp) noexcept {
void accept(Tcp &tcp) {
invoke(&uv_accept, get<uv_stream_t>(), tcp.get<uv_stream_t>());
}
};

View File

@ -33,7 +33,7 @@ public:
bool init() { return initialize<uv_timer_t>(&uv_timer_init); }
void start(Time timeout, Time repeat) { invoke(uv_timer_start, get<uv_timer_t>(), &startCallback, timeout.count(), repeat.count()); }
void start(Time timeout, Time repeat) { invoke(&uv_timer_start, get<uv_timer_t>(), &startCallback, timeout.count(), repeat.count()); }
void stop() { invoke(&uv_timer_stop, get<uv_timer_t>()); }
void again() { invoke(&uv_timer_again, get<uv_timer_t>()); }

View File

@ -30,7 +30,7 @@ public:
return std::shared_ptr<Work>{new Work{std::forward<Args>(args)...}};
}
void queue(Task t) noexcept {
void queue(Task t) {
if(0 == exec<uv_work_t, WorkEvent>(&uv_queue_work, parent(), get<uv_work_t>(), &workCallback)) {
task = std::move(t);
}