minor changes

This commit is contained in:
Michele Caini 2016-07-21 09:27:08 +02:00
parent 34d3974ebc
commit 54307839f3
3 changed files with 15 additions and 23 deletions

View File

@ -34,7 +34,7 @@ public:
void start(std::string f, unsigned int interval) {
file = std::move(f);
invoke(&uv_fs_poll_start, get<uv_fs_poll_t>(), &startCallback, file.c_str(), interval);
invoke(&uv_fs_poll_start, get<uv_fs_poll_t>(), &startCallback, file.data(), interval);
}
void stop() { invoke(&uv_fs_poll_stop, get<uv_fs_poll_t>()); }

View File

@ -77,17 +77,17 @@ public:
bool init() { return initialize<uv_tcp_t>(&uv_tcp_init); }
void noDelay(bool value = false) {
invoke(&uv_tcp_nodelay, get<uv_tcp_t>(), value ? 1 : 0);
invoke(&uv_tcp_nodelay, get<uv_tcp_t>(), value);
}
void keepAlive(bool enable = false, Time time = Time{0}) {
invoke(&uv_tcp_keepalive, get<uv_tcp_t>(), enable ? 1 : 0, time.count());
invoke(&uv_tcp_keepalive, get<uv_tcp_t>(), enable, time.count());
}
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void bind(std::string ip, unsigned int port, Flags<Bind> flags = Flags<Bind>{}) {
typename Traits::Type addr;
Traits::AddrFunc(ip.c_str(), port, &addr);
Traits::AddrFunc(ip.data(), port, &addr);
if(0 == invoke(&uv_tcp_bind, get<uv_tcp_t>(), reinterpret_cast<const sockaddr *>(&addr), flags)) {
addressF = &tAddress<I>;
@ -106,7 +106,7 @@ public:
template<typename I, typename..., typename Traits = details::IpTraits<I>>
void connect(std::string ip, unsigned int port) {
typename Traits::Type addr;
Traits::AddrFunc(ip.c_str(), port, &addr);
Traits::AddrFunc(ip.data(), port, &addr);
std::weak_ptr<Tcp> weak = this->shared_from_this();

View File

@ -19,11 +19,15 @@ class TTY final: public Stream<TTY> {
bool readable)
: Stream{HandleType<uv_tty_t>{}, std::move(ref)},
fd{static_cast<FileDescriptor::Type>(desc)},
rw{readable ? 1 : 0}
rw{readable}
{ }
public:
enum class Mode: unsigned short int { NORMAL, RAW, IO };
enum class Mode: std::underlying_type_t<uv_tty_mode_t> {
NORMAL = UV_TTY_MODE_NORMAL,
RAW = UV_TTY_MODE_RAW,
IO = UV_TTY_MODE_IO
};
template<typename... Args>
static std::shared_ptr<TTY> create(Args&&... args) {
@ -32,23 +36,11 @@ public:
bool init() { return initialize<uv_tty_t>(&uv_tty_init, fd, rw); }
void mode(TTY::Mode m) {
// uv_tty_set_mode is inline, cannot be used with invoke directly
auto wrap = [](auto *handle, auto m) {
void mode(Mode m) {
// uv_tty_set_mode is inline, it cannot be used with invoke directly
invoke([](auto *handle, auto m) {
return uv_tty_set_mode(handle, m);
};
switch(m) {
case TTY::Mode::NORMAL:
invoke(std::move(wrap), get<uv_tty_t>(), UV_TTY_MODE_NORMAL);
break;
case TTY::Mode::RAW:
invoke(std::move(wrap), get<uv_tty_t>(), UV_TTY_MODE_RAW);
break;
case TTY::Mode::IO:
invoke(std::move(wrap), get<uv_tty_t>(), UV_TTY_MODE_IO);
break;
}
}, get<uv_tty_t>(), static_cast<std::underlying_type_t<Mode>>(m));
}
void reset() { invoke(&uv_tty_reset_mode); }