This commit is contained in:
Michele Caini 2016-11-23 12:11:28 +01:00
parent b76da4f869
commit 68bf6c8449
8 changed files with 45 additions and 44 deletions

View File

@ -129,12 +129,12 @@ struct FsEvent<details::UVFsType::READ>
: Event<FsEvent<details::UVFsType::READ>>
{
FsEvent(const char *path, std::unique_ptr<const char[]> data, ssize_t size) noexcept
: path{path}, data{std::move(data)}, size{size}
: path{path}, data{std::move(data)}, size(size)
{ }
const char * path; /*!< The path affecting the request. */
std::unique_ptr<const char[]> data; /*!< A bunch of data read from the given path. */
ssize_t size; /*!< The amount of data read from the given path. */
std::size_t size; /*!< The amount of data read from the given path. */
};
@ -149,11 +149,11 @@ struct FsEvent<details::UVFsType::WRITE>
: Event<FsEvent<details::UVFsType::WRITE>>
{
FsEvent(const char *path, ssize_t size) noexcept
: path{path}, size{size}
: path{path}, size(size)
{ }
const char * path; /*!< The path affecting the request. */
ssize_t size; /*!< The amount of data written to the given path. */
std::size_t size; /*!< The amount of data written to the given path. */
};
@ -168,11 +168,11 @@ struct FsEvent<details::UVFsType::SENDFILE>
: Event<FsEvent<details::UVFsType::SENDFILE>>
{
FsEvent(const char *path, ssize_t size) noexcept
: path{path}, size{size}
: path{path}, size(size)
{ }
const char * path; /*!< The path affecting the request. */
ssize_t size; /*!< The amount of data transferred. */
std::size_t size; /*!< The amount of data transferred. */
};
@ -187,7 +187,7 @@ struct FsEvent<details::UVFsType::STAT>
: Event<FsEvent<details::UVFsType::STAT>>
{
FsEvent(const char *path, Stat stat) noexcept
: path{path}, stat(std::move(stat))
: path{path}, stat{std::move(stat)}
{ }
const char * path; /*!< The path affecting the request. */
@ -206,7 +206,7 @@ struct FsEvent<details::UVFsType::FSTAT>
: Event<FsEvent<details::UVFsType::FSTAT>>
{
FsEvent(const char *path, Stat stat) noexcept
: path{path}, stat(std::move(stat))
: path{path}, stat{std::move(stat)}
{ }
const char * path; /*!< The path affecting the request. */
@ -225,7 +225,7 @@ struct FsEvent<details::UVFsType::LSTAT>
: Event<FsEvent<details::UVFsType::LSTAT>>
{
FsEvent(const char *path, Stat stat) noexcept
: path{path}, stat(std::move(stat))
: path{path}, stat{std::move(stat)}
{ }
const char * path; /*!< The path affecting the request. */
@ -244,11 +244,11 @@ struct FsEvent<details::UVFsType::SCANDIR>
: Event<FsEvent<details::UVFsType::SCANDIR>>
{
FsEvent(const char *path, ssize_t size) noexcept
: path{path}, size{size}
: path{path}, size(size)
{ }
const char * path; /*!< The path affecting the request. */
ssize_t size; /*!< The number of directory entries selected. */
std::size_t size; /*!< The number of directory entries selected. */
};
@ -263,12 +263,12 @@ struct FsEvent<details::UVFsType::READLINK>
: Event<FsEvent<details::UVFsType::READLINK>>
{
explicit FsEvent(const char *path, const char *data, ssize_t size) noexcept
: path{path}, data{data}, size{size}
: path{path}, data{data}, size(size)
{ }
const char * path; /*!< The path affecting the request. */
const char * data; /*!< A bunch of data read from the given path. */
ssize_t size; /*!< The amount of data read from the given path. */
std::size_t size; /*!< The amount of data read from the given path. */
};
@ -457,14 +457,15 @@ public:
* * A bunch of data read from the given path.
* * The amount of data read from the given path.
*/
std::pair<bool, std::pair<std::unique_ptr<const char[]>, ssize_t>>
std::pair<bool, std::pair<std::unique_ptr<const char[]>, std::size_t>>
readSync(int64_t offset, unsigned int len) {
data = std::unique_ptr<char[]>{new char[len]};
buffer = uv_buf_init(data.get(), len);
uv_buf_t bufs[] = { buffer };
auto req = get();
cleanupAndInvokeSync(&uv_fs_read, parent(), req, file, bufs, 1, offset);
return std::make_pair(!(req->result < 0), std::make_pair(std::move(data), req->result));
bool err = req->result < 0;
return std::make_pair(!err, std::make_pair(std::move(data), err ? 0 : std::size_t(req->result)));
}
/**
@ -477,7 +478,7 @@ public:
* @param len The lenght of the submitted data.
* @param offset Offset, as described in the official documentation.
*/
void write(std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
void write(std::unique_ptr<char[]> data, std::size_t len, int64_t offset) {
this->data = std::move(data);
uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) };
cleanupAndInvoke(&uv_fs_write, parent(), get(), file, bufs, 1, offset, &fsResultCallback<Type::WRITE>);
@ -494,12 +495,13 @@ public:
* * A boolean value that is true in case of success, false otherwise.
* * The amount of data written to the given path.
*/
std::pair<bool, ssize_t> writeSync(std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
std::pair<bool, std::size_t> writeSync(std::unique_ptr<char[]> data, std::size_t len, int64_t offset) {
this->data = std::move(data);
uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) };
auto req = get();
cleanupAndInvokeSync(&uv_fs_write, parent(), req, file, bufs, 1, offset);
return std::make_pair(!(req->result < 0), req->result);
bool err = req->result < 0;
return std::make_pair(!err, err ? 0 : std::size_t(req->result));
}
/**
@ -598,7 +600,7 @@ public:
* @param offset Offset, as described in the official documentation.
* @param length Length, as described in the official documentation.
*/
void sendfile(FileHandle out, int64_t offset, size_t length) {
void sendfile(FileHandle out, int64_t offset, std::size_t length) {
cleanupAndInvoke(&uv_fs_sendfile, parent(), get(), out, file, offset, length, &fsResultCallback<Type::SENDFILE>);
}
@ -613,10 +615,11 @@ public:
* * A boolean value that is true in case of success, false otherwise.
* * The amount of data transferred.
*/
std::pair<bool, ssize_t> sendfileSync(FileHandle out, int64_t offset, size_t length) {
std::pair<bool, std::size_t> sendfileSync(FileHandle out, int64_t offset, std::size_t length) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_sendfile, parent(), req, out, file, offset, length);
return std::make_pair(!(req->result < 0), req->result);
bool err = req->result < 0;
return std::make_pair(!err, err ? 0 : std::size_t(req->result));
}
/**
@ -867,10 +870,11 @@ public:
* * A boolean value that is true in case of success, false otherwise.
* * The number of directory entries selected.
*/
std::pair<bool, ssize_t> scandirSync(std::string path, int flags) {
std::pair<bool, std::size_t> scandirSync(std::string path, int flags) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_scandir, parent(), req, path.data(), flags);
return std::make_pair(!(req->result < 0), req->result);
bool err = req->result < 0;
return std::make_pair(!err, err ? 0 : std::size_t(req->result));
}
/**
@ -1151,11 +1155,12 @@ public:
* * A bunch of data read from the given path.
* * The amount of data read from the given path.
*/
std::pair<bool, std::pair<const char *, ssize_t>>
std::pair<bool, std::pair<const char *, std::size_t>>
readlinkSync(std::string path) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_readlink, parent(), req, path.data());
return std::make_pair(!(req->result < 0), std::make_pair(static_cast<char *>(req->ptr), req->result));
bool err = req->result < 0;
return std::make_pair(!err, std::make_pair(static_cast<char *>(req->ptr), err ? 0 : std::size_t(req->result)));
}
/**

View File

@ -21,7 +21,7 @@ namespace uvw {
*/
struct FsPollEvent: Event<FsPollEvent> {
explicit FsPollEvent(Stat prev, Stat curr) noexcept
: prev(std::move(prev)), curr(std::move(curr))
: prev{std::move(prev)}, curr{std::move(curr)}
{ }
Stat prev; /*!< The old Stat struct. */

View File

@ -20,8 +20,7 @@ namespace uvw {
*/
class SharedLib final {
explicit SharedLib(std::shared_ptr<Loop> ref, std::string filename) noexcept
: pLoop{std::move(ref)},
lib{}
: pLoop{std::move(ref)}, lib{}
{
opened = (0 == uv_dlopen(filename.data(), &lib));
}

View File

@ -18,7 +18,7 @@ namespace uvw {
* It will be emitted by SignalHandle according with its functionalities.
*/
struct SignalEvent: Event<SignalEvent> {
explicit SignalEvent(int sig) noexcept: signum(sig) { }
explicit SignalEvent(int sig) noexcept: signum{sig} { }
int signum; /*!< The signal being monitored by this handle. */
};

View File

@ -63,11 +63,11 @@ struct WriteEvent: Event<WriteEvent> { };
*/
struct DataEvent: Event<DataEvent> {
explicit DataEvent(std::unique_ptr<const char[]> data, ssize_t length) noexcept
: data{std::move(data)}, length{length}
: data{std::move(data)}, length(length)
{ }
std::unique_ptr<const char[]> data; /*!< A bunch of data read on the stream. */
ssize_t length; /*!< The amount of data read on the stream. */
std::size_t length; /*!< The amount of data read on the stream. */
};
@ -273,7 +273,7 @@ public:
* @param data The data to be written to the stream.
* @param len The lenght of the submitted data.
*/
void write(std::unique_ptr<char[]> data, ssize_t len) {
void write(std::unique_ptr<char[]> data, std::size_t len) {
const uv_buf_t bufs[] = { uv_buf_init(data.release(), len) };
auto listener = [ptr = this->shared_from_this()](const auto &event, details::WriteReq &) {
@ -304,7 +304,7 @@ public:
* @param len The lenght of the submitted data.
*/
template<typename S>
void write(S &send, std::unique_ptr<char[]> data, ssize_t len) {
void write(S &send, std::unique_ptr<char[]> data, std::size_t len) {
const uv_buf_t bufs[] = { uv_buf_init(data.release(), len) };
auto listener = [ptr = this->shared_from_this()](const auto &event, details::WriteReq &) {
@ -328,7 +328,7 @@ public:
* @param len The lenght of the submitted data.
* @return Number of bytes written.
*/
int tryWrite(std::unique_ptr<char[]> data, ssize_t len) {
int tryWrite(std::unique_ptr<char[]> data, std::size_t len) {
uv_buf_t bufs[] = { uv_buf_init(data.get(), len) };
auto bw = uv_try_write(this->template get<uv_stream_t>(), bufs, 1);

View File

@ -31,10 +31,7 @@ class Thread final {
}
explicit Thread(std::shared_ptr<Loop> ref, InternalTask t, std::shared_ptr<void> d = nullptr) noexcept
: pLoop{std::move(ref)},
data{std::move(d)},
thread{},
task{std::move(t)}
: pLoop{std::move(ref)}, data{std::move(d)}, thread{}, task{std::move(t)}
{ }
public:

View File

@ -33,11 +33,11 @@ struct SendEvent: Event<SendEvent> { };
*/
struct UDPDataEvent: Event<UDPDataEvent> {
explicit UDPDataEvent(Addr sender, std::unique_ptr<const char[]> data, ssize_t length, bool partial) noexcept
: data{std::move(data)}, length{length}, sender(std::move(sender)), partial{partial}
: data{std::move(data)}, length(length), sender{std::move(sender)}, partial{partial}
{ }
std::unique_ptr<const char[]> data; /*!< A bunch of data read on the stream. */
ssize_t length; /*!< The amount of data read on the stream. */
std::size_t length; /*!< The amount of data read on the stream. */
Addr sender; /*!< A valid instance of Addr. */
bool partial; /*!< True if the message was truncated, false otherwise. */
};
@ -318,7 +318,7 @@ public:
* @param len The lenght of the submitted data.
*/
template<typename I = IPv4>
void send(std::string ip, unsigned int port, std::unique_ptr<char[]> data, ssize_t len) {
void send(std::string ip, unsigned int port, std::unique_ptr<char[]> data, std::size_t len) {
typename details::IpTraits<I>::Type addr;
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);
@ -347,7 +347,7 @@ public:
* @return Number of bytes written.
*/
template<typename I = IPv4>
int trySend(std::string ip, unsigned int port, std::unique_ptr<char[]> data, ssize_t len) {
int trySend(std::string ip, unsigned int port, std::unique_ptr<char[]> data, std::size_t len) {
typename details::IpTraits<I>::Type addr;
details::IpTraits<I>::addrFunc(ip.data(), port, &addr);

View File

@ -104,13 +104,13 @@ TEST(FileReq, RWSync) {
auto writeR = request->writeSync(std::unique_ptr<char[]>{new char[1]{ 42 }}, 1, 0);
ASSERT_TRUE(writeR.first);
ASSERT_EQ(writeR.second, 1);
ASSERT_EQ(writeR.second, std::size_t{1});
auto readR = request->readSync(0, 1);
ASSERT_TRUE(readR.first);
ASSERT_EQ(readR.second.first[0], 42);
ASSERT_EQ(readR.second.second, 1);
ASSERT_EQ(readR.second.second, std::size_t{1});
ASSERT_TRUE(request->closeSync());
loop->run();