Minor consistency updates

This commit is contained in:
Michael Theall 2020-05-18 20:45:46 -05:00
parent ba87a2b599
commit ab5051082c
6 changed files with 73 additions and 34 deletions

View File

@ -20,6 +20,8 @@
#pragma once
#include "ioBuffer.h"
#include <dirent.h>
#include <cstdint>
@ -75,34 +77,44 @@ public:
/// \brief Seek to file position
/// \param pos_ File position
/// \param origin_ Reference position (\sa std::fseek)
ssize_t seek (std::size_t pos_, int origin_);
std::make_signed_t<std::size_t> seek (std::size_t pos_, int origin_);
/// \brief Read data
/// \param data_ Output buffer
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \note Can return partial reads
ssize_t read (void *data_, std::size_t size_);
std::make_signed_t<std::size_t> read (void *buffer_, std::size_t size_);
/// \brief Read data
/// \param buffer_ Output buffer
/// \note Can return partial reads
std::make_signed_t<std::size_t> read (IOBuffer &buffer_);
/// \brief Read line
std::string_view readLine ();
/// \brief Read data
/// \param data_ Output buffer
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \note Fails on partial reads and errors
bool readAll (void *data_, std::size_t size_);
bool readAll (void *buffer_, std::size_t size_);
/// \brief Write data
/// \param data_ Input data
/// \param buffer_ Input data
/// \param size_ Size to write
/// \note Can return partial writes
ssize_t write (void const *data_, std::size_t size_);
std::make_signed_t<std::size_t> write (void const *buffer_, std::size_t size_);
/// \brief Write data
/// \param data_ Input data
/// \param buffer_ Input data
/// \note Can return partial writes
std::make_signed_t<std::size_t> write (IOBuffer &buffer_);
/// \brief Write data
/// \param buffer_ Input data
/// \param size_ Size to write
/// \note Fails on partials writes and errors
bool writeAll (void const *data_, std::size_t size_);
bool writeAll (void const *buffer_, std::size_t size_);
private:
/// \brief Underlying std::FILE*

View File

@ -118,23 +118,22 @@ public:
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \param oob_ Whether to read from out-of-band
ssize_t read (void *buffer_, std::size_t size_, bool oob_ = false);
std::make_signed_t<std::size_t> read (void *buffer_, std::size_t size_, bool oob_ = false);
/// \brief Read data
/// \param buffer_ Output buffer
/// \param size_ Size to read
/// \param oob_ Whether to read from out-of-band
ssize_t read (IOBuffer &buffer_, bool oob_ = false);
std::make_signed_t<std::size_t> read (IOBuffer &buffer_, bool oob_ = false);
/// \brief Write data
/// \param buffer_ Input buffer
/// \param size_ Size to write
ssize_t write (void const *buffer_, std::size_t size_);
std::make_signed_t<std::size_t> write (void const *buffer_, std::size_t size_);
/// \brief Write data
/// \param buffer_ Input buffer
/// \param size_ Size to write
ssize_t write (IOBuffer &buffer_);
std::make_signed_t<std::size_t> write (IOBuffer &buffer_);
/// \brief Local name
SockAddr const &sockName () const;

View File

@ -25,7 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef CLASSIC
#include "imgui_ctru.h"

View File

@ -20,6 +20,7 @@
#include "fs.h"
#include <cassert>
#include <cinttypes>
#include <cstdio>
#include <string>
@ -134,14 +135,28 @@ void fs::File::close ()
m_fp.reset ();
}
ssize_t fs::File::seek (std::size_t const pos_, int const origin_)
std::make_signed_t<std::size_t> fs::File::seek (std::size_t const pos_, int const origin_)
{
return std::fseek (m_fp.get (), pos_, origin_);
}
ssize_t fs::File::read (void *const data_, std::size_t const size_)
std::make_signed_t<std::size_t> fs::File::read (void *const buffer_, std::size_t const size_)
{
return std::fread (data_, 1, size_, m_fp.get ());
assert (buffer_);
assert (size_ > 0);
return std::fread (buffer_, 1, size_, m_fp.get ());
}
std::make_signed_t<std::size_t> fs::File::read (IOBuffer &buffer_)
{
assert (buffer_.freeSize () > 0);
auto const rc = read (buffer_.freeArea (), buffer_.freeSize ());
if (rc > 0)
buffer_.markUsed (rc);
return rc;
}
std::string_view fs::File::readLine ()
@ -165,11 +180,14 @@ std::string_view fs::File::readLine ()
}
}
bool fs::File::readAll (void *const data_, std::size_t const size_)
bool fs::File::readAll (void *const buffer_, std::size_t const size_)
{
auto p = static_cast<char *> (data_);
std::size_t bytes = 0;
assert (buffer_);
assert (size_ > 0);
auto p = static_cast<char *> (buffer_);
std::size_t bytes = 0;
while (bytes < size_)
{
auto const rc = read (p, size_ - bytes);
@ -183,16 +201,19 @@ bool fs::File::readAll (void *const data_, std::size_t const size_)
return true;
}
ssize_t fs::File::write (void const *const data_, std::size_t const size_)
std::make_signed_t<std::size_t> fs::File::write (void const *const buffer_, std::size_t const size_)
{
return std::fwrite (data_, 1, size_, m_fp.get ());
return std::fwrite (buffer_, 1, size_, m_fp.get ());
}
bool fs::File::writeAll (void const *const data_, std::size_t const size_)
bool fs::File::writeAll (void const *const buffer_, std::size_t const size_)
{
auto p = static_cast<char const *> (data_);
std::size_t bytes = 0;
assert (buffer_);
assert (size_ > 0);
auto p = static_cast<char const *> (buffer_);
std::size_t bytes = 0;
while (bytes < size_)
{
auto const rc = write (p, size_ - bytes);

View File

@ -355,6 +355,7 @@ void FtpServer::showMenu ()
m_getMTimeSetting = m_config->getMTime ();
#endif
info ("Open \"Settings\" popup\n");
ImGui::OpenPopup ("Settings");
}

View File

@ -238,7 +238,7 @@ bool Socket::setNonBlocking (bool const nonBlocking_)
bool Socket::setReuseAddress (bool const reuse_)
{
int reuse = reuse_;
int const reuse = reuse_;
if (::setsockopt (m_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse)) != 0)
{
error ("setsockopt(SO_REUSEADDR, %s): %s\n", reuse_ ? "yes" : "no", std::strerror (errno));
@ -250,7 +250,7 @@ bool Socket::setReuseAddress (bool const reuse_)
bool Socket::setRecvBufferSize (std::size_t const size_)
{
int size = size_;
int const size = size_;
if (::setsockopt (m_fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size)) != 0)
{
error ("setsockopt(SO_RCVBUF, %zu): %s\n", size_, std::strerror (errno));
@ -262,7 +262,7 @@ bool Socket::setRecvBufferSize (std::size_t const size_)
bool Socket::setSendBufferSize (std::size_t const size_)
{
int size = size_;
int const size = size_;
if (::setsockopt (m_fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) != 0)
{
error ("setsockopt(SO_SNDBUF, %zu): %s\n", size_, std::strerror (errno));
@ -272,10 +272,12 @@ bool Socket::setSendBufferSize (std::size_t const size_)
return true;
}
ssize_t Socket::read (void *const buffer_, std::size_t const size_, bool const oob_)
std::make_signed_t<std::size_t>
Socket::read (void *const buffer_, std::size_t const size_, bool const oob_)
{
assert (buffer_);
assert (size_);
auto const rc = ::recv (m_fd, buffer_, size_, oob_ ? MSG_OOB : 0);
if (rc < 0 && errno != EWOULDBLOCK)
error ("recv: %s\n", std::strerror (errno));
@ -283,8 +285,10 @@ ssize_t Socket::read (void *const buffer_, std::size_t const size_, bool const o
return rc;
}
ssize_t Socket::read (IOBuffer &buffer_, bool const oob_)
std::make_signed_t<std::size_t> Socket::read (IOBuffer &buffer_, bool const oob_)
{
assert (buffer_.freeSize () > 0);
auto const rc = read (buffer_.freeArea (), buffer_.freeSize (), oob_);
if (rc > 0)
buffer_.markUsed (rc);
@ -292,10 +296,11 @@ ssize_t Socket::read (IOBuffer &buffer_, bool const oob_)
return rc;
}
ssize_t Socket::write (void const *const buffer_, std::size_t const size_)
std::make_signed_t<std::size_t> Socket::write (void const *const buffer_, std::size_t const size_)
{
assert (buffer_);
assert (size_);
assert (size_ > 0);
auto const rc = ::send (m_fd, buffer_, size_, 0);
if (rc < 0 && errno != EWOULDBLOCK)
error ("send: %s\n", std::strerror (errno));
@ -303,8 +308,10 @@ ssize_t Socket::write (void const *const buffer_, std::size_t const size_)
return rc;
}
ssize_t Socket::write (IOBuffer &buffer_)
std::make_signed_t<std::size_t> Socket::write (IOBuffer &buffer_)
{
assert (buffer_.usedSize () > 0);
auto const rc = write (buffer_.usedArea (), buffer_.usedSize ());
if (rc > 0)
buffer_.markFree (rc);