Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support for uvw 3.0 #102

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions 3rd/uvw/uvw.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#include "uvw/async.hpp"
#include "uvw/check.hpp"
#include "uvw/dns.hpp"
#include "uvw/fs.hpp"
#include "uvw/fs_event.hpp"
#include "uvw/fs_poll.hpp"
#include "uvw/idle.hpp"
#include "uvw/lib.hpp"
#include "uvw/loop.hpp"
#include "uvw/pipe.hpp"
#include "uvw/poll.hpp"
#include "uvw/prepare.hpp"
#include "uvw/process.hpp"
#include "uvw/signal.hpp"
#include "uvw/tcp.hpp"
#include "uvw/thread.hpp"
#include "uvw/timer.hpp"
#include "uvw/tty.hpp"
#include "uvw/udp.hpp"
#include "uvw/util.hpp"
#include "uvw/work.hpp"
#include "uvw/async.h"
#include "uvw/check.h"
#include "uvw/config.h"
#include "uvw/dns.h"
#include "uvw/emitter.h"
#include "uvw/enum.hpp"
#include "uvw/fs.h"
#include "uvw/fs_event.h"
#include "uvw/fs_poll.h"
#include "uvw/handle.hpp"
#include "uvw/idle.h"
#include "uvw/lib.h"
#include "uvw/loop.h"
#include "uvw/pipe.h"
#include "uvw/poll.h"
#include "uvw/prepare.h"
#include "uvw/process.h"
#include "uvw/request.hpp"
#include "uvw/resource.hpp"
#include "uvw/signal.h"
#include "uvw/tcp.h"
#include "uvw/thread.h"
#include "uvw/timer.h"
#include "uvw/tty.h"
#include "uvw/udp.h"
#include "uvw/util.h"
#include "uvw/uv_type.hpp"
#include "uvw/work.h"
22 changes: 22 additions & 0 deletions 3rd/uvw/uvw/async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef UVW_AS_LIB
# include "async.h"
#endif

#include "config.h"

namespace uvw {

UVW_INLINE void async_handle::send_callback(uv_async_t *hndl) {
async_handle &async = *(static_cast<async_handle *>(hndl->data));
async.publish(async_event{});
}

UVW_INLINE int async_handle::init() {
return leak_if(uv_async_init(parent().raw(), raw(), &send_callback));
}

UVW_INLINE int async_handle::send() {
return uv_async_send(raw());
}

} // namespace uvw
58 changes: 58 additions & 0 deletions 3rd/uvw/uvw/async.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef UVW_ASYNC_INCLUDE_H
#define UVW_ASYNC_INCLUDE_H

#include <uv.h>
#include "handle.hpp"
#include "loop.h"

namespace uvw {

/*! @brief Async event. */
struct async_event {};

/**
* @brief The async handle.
*
* Async handles allow the user to _wakeup_ the event loop and get an event
* emitted from another thread.
*
* To create an `async_handle` through a `loop`, no arguments are required.
*/
class async_handle final: public handle<async_handle, uv_async_t, async_event> {
static void send_callback(uv_async_t *hndl);

public:
using handle::handle;

/**
* @brief Initializes the handle.
*
* Unlike other handle initialization functions, it immediately starts the
* handle.
*
* @return Underlying return value.
*/
int init() final;

/**
* @brief Wakeups the event loop and emits the async event.
*
* It’s safe to call this function from any thread.<br/>
* An async event is emitted on the loop thread.
*
* See the official
* [documentation](http://docs.libuv.org/en/v1.x/async.html#c.uv_async_send)
* for further details.
*
* @return Underlying return value.
*/
int send();
};

} // namespace uvw

#ifndef UVW_AS_LIB
# include "async.cpp"
#endif

#endif // UVW_ASYNC_INCLUDE_H
67 changes: 0 additions & 67 deletions 3rd/uvw/uvw/async.hpp

This file was deleted.

26 changes: 26 additions & 0 deletions 3rd/uvw/uvw/check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifdef UVW_AS_LIB
# include "check.h"
#endif

#include "config.h"

namespace uvw {

UVW_INLINE void check_handle::start_callback(uv_check_t *hndl) {
check_handle &check = *(static_cast<check_handle *>(hndl->data));
check.publish(check_event{});
}

UVW_INLINE int check_handle::init() {
return leak_if(uv_check_init(parent().raw(), raw()));
}

UVW_INLINE int check_handle::start() {
return uv_check_start(raw(), &start_callback);
}

UVW_INLINE int check_handle::stop() {
return uv_check_stop(raw());
}

} // namespace uvw
56 changes: 56 additions & 0 deletions 3rd/uvw/uvw/check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef UVW_CHECK_INCLUDE_H
#define UVW_CHECK_INCLUDE_H

#include <uv.h>
#include "handle.hpp"
#include "loop.h"

namespace uvw {

/*! @brief Check event. */
struct check_event {};

/**
* @brief The check handle.
*
* Check handles will emit a check event once per loop iteration, right after
* polling for I/O.
*
* To create a `check_handle` through a `loop`, no arguments are required.
*/
class check_handle final: public handle<check_handle, uv_check_t, check_event> {
static void start_callback(uv_check_t *hndl);

public:
using handle::handle;

/**
* @brief Initializes the handle.
* @return Underlying return value.
*/
int init() final;

/**
* @brief Starts the handle.
*
* A check event will be emitted once per loop iteration, right after
* polling for I/O.
*
* @return Underlying return value.
*/
int start();

/**
* @brief Stops the handle.
* @return Underlying return value.
*/
int stop();
};

} // namespace uvw

#ifndef UVW_AS_LIB
# include "check.cpp"
#endif

#endif // UVW_CHECK_INCLUDE_H
66 changes: 0 additions & 66 deletions 3rd/uvw/uvw/check.hpp

This file was deleted.

10 changes: 10 additions & 0 deletions 3rd/uvw/uvw/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef UVW_CONFIG_H
#define UVW_CONFIG_H

#ifndef UVW_AS_LIB
# define UVW_INLINE inline
#else
# define UVW_INLINE
#endif

#endif
Loading