Skip to content

Commit

Permalink
now working with libuv v1.31.x
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 10, 2019
1 parent 7495813 commit ea4b6c8
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 146 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exist a valid `libuv` wrapper in C++. That's all.
To be able to use `uvw`, users must provide the following system-wide tools:
* A full-featured compiler that supports at least C++14.
* A full-featured compiler that supports at least C++17.
* `libuv` (which version depends on the tag of `uvw` in use).
The requirements below are mandatory to compile the tests and to extract the
Expand Down Expand Up @@ -169,10 +169,7 @@ for the latest version.

The documentation is mostly inspired by the official
[libuv API documentation](http://docs.libuv.org/en/v1.x/) for obvious
reasons.<br/>
If you are mainly interested in the way `uvw` imports `libuv` in a `cmake` based
project, I suggest you to take a look at
[this](https://github.com/skypjack/libuv_cmake) repository instead.
reasons.

## Tests

Expand Down
2 changes: 1 addition & 1 deletion cmake/in/deps.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ExternalProject_Add(
ExternalProject_Add(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.30.1
GIT_TAG v1.31.0
SOURCE_DIR @LIBUV_DEPS_DIR@
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
63 changes: 62 additions & 1 deletion src/uvw/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ enum class UVFsType: std::underlying_type_t<uv_fs_type> {
LCHOWN = UV_FS_LCHOWN,
OPENDIR = UV_FS_OPENDIR,
READDIR = UV_FS_READDIR,
CLOSEDIR = UV_FS_CLOSEDIR
CLOSEDIR = UV_FS_CLOSEDIR,
STATFS = UV_FS_STATFS
};


Expand All @@ -76,6 +77,7 @@ enum class UVFileOpenFlags: int {
DSYNC = UV_FS_O_DSYNC,
EXCL = UV_FS_O_EXCL,
EXLOCK = UV_FS_O_EXLOCK,
FILEMAP = UV_FS_O_FILEMAP,
NOATIME = UV_FS_O_NOATIME,
NOCTTY = UV_FS_O_NOCTTY,
NOFOLLOW = UV_FS_O_NOFOLLOW,
Expand Down Expand Up @@ -149,6 +151,7 @@ enum class UVSymLinkFlags: int {
* * `FsRequest::Type::OPENDIR`
* * `FsRequest::Type::READDIR`
* * `FsRequest::Type::CLOSEDIR`
* * `FsRequest::Type::STATFS`
*
* It will be emitted by FsReq and/or FileReq according with their
* functionalities.
Expand Down Expand Up @@ -268,6 +271,23 @@ struct FsEvent<details::UVFsType::LSTAT> {
};


/**
* @brief FsEvent event specialization for `FsRequest::Type::STATFS`.
*
* It will be emitted by FsReq and/or FileReq according with their
* functionalities.
*/
template<>
struct FsEvent<details::UVFsType::STATFS> {
FsEvent(const char *pathname, Statfs curr) noexcept
: path{pathname}, statfs{std::move(curr)}
{}

const char * path; /*!< The path affecting the request. */
Statfs statfs; /*!< An initialized instance of Statfs. */
};


/**
* @brief FsEvent event specialization for `FsRequest::Type::SCANDIR`.
*
Expand Down Expand Up @@ -352,6 +372,12 @@ class FsRequest: public Request<T, uv_fs_t> {
else { ptr->publish(FsEvent<e>{req->path, req->statbuf}); }
}

static void fsStatfsCallback(uv_fs_t *req) {
auto ptr = Request<T, uv_fs_t>::reserve(req);
if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
else { ptr->publish(FsEvent<Type::STATFS>{req->path, *static_cast<Statfs *>(req->ptr)}); }
}

template<typename... Args>
void cleanupAndInvoke(Args&&... args) {
uv_fs_req_cleanup(this->get());
Expand Down Expand Up @@ -461,6 +487,7 @@ class FileReq final: public FsRequest<FileReq> {
* * `FileReq::FileOpen::DSYNC`
* * `FileReq::FileOpen::EXCL`
* * `FileReq::FileOpen::EXLOCK`
* * `FileReq::FileOpen::FILEMAP`
* * `FileReq::FileOpen::NOATIME`
* * `FileReq::FileOpen::NOCTTY`
* * `FileReq::FileOpen::NOFOLLOW`
Expand Down Expand Up @@ -500,6 +527,7 @@ class FileReq final: public FsRequest<FileReq> {
* * `FileReq::FileOpen::DSYNC`
* * `FileReq::FileOpen::EXCL`
* * `FileReq::FileOpen::EXLOCK`
* * `FileReq::FileOpen::FILEMAP`
* * `FileReq::FileOpen::NOATIME`
* * `FileReq::FileOpen::NOCTTY`
* * `FileReq::FileOpen::NOFOLLOW`
Expand Down Expand Up @@ -1106,6 +1134,39 @@ class FsReq final: public FsRequest<FsReq> {
return std::make_pair(!(req->result < 0), req->statbuf);
}

/**
* @brief Async [statfs](http://linux.die.net/man/2/statfs).
*
* Emit a `FsEvent<FsReq::Type::STATFS>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* Any fields in the resulting object that are not supported by the
* underlying operating system are set to zero.
*
* @param path Path, as described in the official documentation.
*/
void stasfs(std::string path) {
cleanupAndInvoke(&uv_fs_statfs, parent(), get(), path.data(), &fsStatfsCallback);
}

/**
* @brief Sync [statfs](http://linux.die.net/man/2/statfs).
*
* Any fields in the resulting object that are not supported by the
* underlying operating system are set to zero.
*
* @param path Path, as described in the official documentation.
*
* @return A `std::pair` composed as it follows:
* * A boolean value that is true in case of success, false otherwise.
* * An initialized instance of Statfs.
*/
std::pair<bool, Statfs> statfsSync(std::string path) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_statfs, parent(), req, path.data());
return std::make_pair(!(req->result < 0), *static_cast<uv_statfs_t *>(req->ptr));
}

/**
* @brief Async [rename](http://linux.die.net/man/2/rename).
*
Expand Down
1 change: 1 addition & 0 deletions src/uvw/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ constexpr FileHandle StdERR{2}; /*!< Placeholder for stderr descriptor. */

using TimeSpec = uv_timespec_t; /*!< Library equivalent for uv_timespec_t. */
using Stat = uv_stat_t; /*!< Library equivalent for uv_stat_t. */
using Statfs = uv_statfs_t; /*!< Library equivalent for uv_statfs_t. */
using Uid = uv_uid_t; /*!< Library equivalent for uv_uid_t. */
using Gid = uv_gid_t; /*!< Library equivalent for uv_gid_t. */

Expand Down
2 changes: 0 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ ADD_UVW_TEST(idle uvw/idle.cpp)
ADD_UVW_LIB_TEST(lib uvw/lib.cpp)
ADD_UVW_TEST(loop uvw/loop.cpp)
ADD_UVW_DIR_TEST(pipe uvw/pipe.cpp)
ADD_UVW_TEST(poll uvw/poll.cpp)
ADD_UVW_TEST(prepare uvw/prepare.cpp)
ADD_UVW_TEST(process uvw/process.cpp)
ADD_UVW_TEST(request uvw/request.cpp)
ADD_UVW_TEST(resource uvw/resource.cpp)
ADD_UVW_TEST(signal uvw/signal.cpp)
ADD_UVW_TEST(stream uvw/stream.cpp)
ADD_UVW_TEST(tcp uvw/tcp.cpp)
ADD_UVW_TEST(thread uvw/thread.cpp)
ADD_UVW_TEST(timer uvw/timer.cpp)
ADD_UVW_TEST(tty uvw/tty.cpp)
ADD_UVW_TEST(udp uvw/udp.cpp)
Expand Down
2 changes: 0 additions & 2 deletions test/uvw/file_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ TEST(FileReq, RWSync) {
}



TEST(FileReq, Stat) {
const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"};

Expand Down Expand Up @@ -228,7 +227,6 @@ TEST(FileReq, Stat) {
}



TEST(FileReq, StatSync) {
const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"};

Expand Down
22 changes: 0 additions & 22 deletions test/uvw/fs_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ TEST(FsReq, MkdtempAndRmdirSync) {
}


/*
TEST(FsReq, Scandir) {
// TODO
}
TEST(FsReq, ScandirSync) {
// TODO
}
*/


TEST(FsReq, Stat) {
const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"};

Expand Down Expand Up @@ -267,16 +255,6 @@ TEST(FsReq, RenameSync) {
}


TEST(FsReq, CopyFile) {
// TODO
}


TEST(FsReq, CopyFileSync) {
// TODO
}


TEST(FsReq, Access) {
const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"};

Expand Down
10 changes: 0 additions & 10 deletions test/uvw/pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,3 @@ TEST(Pipe, Shutdown) {

loop->run();
}


TEST(Pipe, TODO) {
auto loop = uvw::Loop::getDefault();
auto handle = uvw::PipeHandle::create(loop);

handle = nullptr;

// TODO
}
12 changes: 0 additions & 12 deletions test/uvw/poll.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions test/uvw/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ TEST(Process, StdIO) {
pipe->close();
loop->run();
}


TEST(Process, TODO) {
auto loop = uvw::Loop::getDefault();
auto handle = uvw::ProcessHandle::create(loop);

handle = nullptr;

// TODO
}
11 changes: 0 additions & 11 deletions test/uvw/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,3 @@ struct FakeStreamHandle: uvw::StreamHandle<FakeStreamHandle, fake_stream_t> {
template<typename... Args>
bool init(Args&&...) { return true; }
};


TEST(Stream, TODO) {
auto loop = uvw::Loop::getDefault();
auto handle = FakeStreamHandle::create(loop);

handle = nullptr;

// TODO

}
70 changes: 0 additions & 70 deletions test/uvw/thread.cpp

This file was deleted.

0 comments on commit ea4b6c8

Please sign in to comment.