delete priv;
}
-unsigned Asset::do_read(char *buf, unsigned size)
+size_t Asset::do_read(char *buf, size_t size)
{
+ // The function actually returns an int, despite taking size_t
int ret = AAsset_read(priv->asset, buf, size);
if(ret<0)
throw runtime_error("Asset::do_read");
throw logic_error("Asset::set_inherit");
}
-unsigned Asset::do_write(const char *, unsigned)
+size_t Asset::do_write(const char *, size_t)
{
throw invalid_access(M_WRITE);
}
virtual void set_inherit(bool);
private:
- virtual unsigned do_write(const char *, unsigned);
- virtual unsigned do_read(char *, unsigned);
+ virtual std::size_t do_write(const char *, std::size_t);
+ virtual std::size_t do_read(char *, std::size_t);
public:
virtual const Handle &get_handle(Mode);
delete priv;
}
-unsigned Asset::do_read(char *buf, unsigned size)
+size_t Asset::do_read(char *buf, size_t size)
{
return priv->file->read(buf, size);
}
state.apply_to(handle);
}
-unsigned Serial::do_write(const char *buf, unsigned size)
+size_t Serial::do_write(const char *buf, size_t size)
{
if(size==0)
return 0;
return sys_write(handle, buf, size);
}
-unsigned Serial::do_read(char *buf, unsigned size)
+size_t Serial::do_read(char *buf, size_t size)
{
if(size==0)
return 0;
- unsigned ret = reader.read(buf, size);
+ size_t ret = reader.read(buf, size);
if(ret==0)
set_eof();
void set_parameters(const std::string &);
private:
- virtual unsigned do_write(const char *, unsigned);
- virtual unsigned do_read(char *, unsigned);
+ virtual std::size_t do_write(const char *, std::size_t);
+ virtual std::size_t do_read(char *, std::size_t);
public:
virtual const Handle &get_handle(Mode);
namespace Msp {
namespace IO {
-unsigned read_all(Base &obj, char *buf, unsigned size)
+size_t read_all(Base &obj, char *buf, size_t size)
{
- unsigned pos = 0;
+ size_t pos = 0;
while(pos<size)
pos += obj.read(buf+pos, size-pos);
#ifndef MSP_IO_UTILS_H_
#define MSP_IO_UTILS_H_
+#include <cstddef>
+
namespace Msp {
namespace IO {
Note: If the data is not immediately available and the object is in non-blocking
mode, this function effectively becomes a busyloop until it can get more
data. */
-unsigned read_all(Base &, char *, unsigned);
+std::size_t read_all(Base &, char *, std::size_t);
} // namespace IO
} // namespace Msp
{
OVERLAPPED overlapped;
Handle event;
- unsigned buf_size = 0;
+ size_t buf_size = 0;
char *buffer = 0;
- unsigned buf_avail = 0;
+ size_t buf_avail = 0;
char *buf_next = 0;
bool pending = false;
bool eof = false;