implemented fdinbuf and fdistream
This commit is contained in:
parent
7bcf15bd28
commit
250e5cbf46
@ -7,3 +7,29 @@
|
||||
//
|
||||
|
||||
#include "libscio.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace sc::io;
|
||||
|
||||
std::streambuf::int_type fdinbuf::uflow() {
|
||||
return _ch;
|
||||
}
|
||||
|
||||
std::streambuf::int_type fdinbuf::underflow() {
|
||||
char c;
|
||||
int num = read(_fd, &c, 1);
|
||||
if (num <= 0) {
|
||||
_ch = EOF;
|
||||
}
|
||||
_ch = c;
|
||||
return _ch;
|
||||
}
|
||||
|
||||
std::streamsize fdinbuf::xsgetn(char* s, std::streamsize n) {
|
||||
return read(_fd, s, n);
|
||||
}
|
||||
|
24
libscio.hpp
24
libscio.hpp
@ -32,26 +32,44 @@ namespace sc {
|
||||
|
||||
class fdostream : public std::ostream {
|
||||
public:
|
||||
fdostream(int fd) : std::ostream(&_buf), _buf(fd) {}
|
||||
fdostream(int fd) : std::ostream(&_outbuf), _outbuf(fd) {}
|
||||
|
||||
protected:
|
||||
fdoutbuf _buf;
|
||||
fdoutbuf _outbuf;
|
||||
};
|
||||
|
||||
class fdinbuf : public std::streambuf {
|
||||
public:
|
||||
fdinbuf(int fd) : _fd(fd) {}
|
||||
|
||||
protected:
|
||||
int _fd;
|
||||
int_type _ch {EOF};
|
||||
|
||||
int_type uflow() override;
|
||||
int_type underflow() override;
|
||||
std::streamsize xsgetn(char* s, std::streamsize n) override;
|
||||
};
|
||||
|
||||
class fdistream : public std::istream {
|
||||
public:
|
||||
fdistream(int fd) : std::istream(&_inbuf), _inbuf(fd) {}
|
||||
|
||||
protected:
|
||||
fdinbuf _inbuf;
|
||||
};
|
||||
|
||||
class fdstream : public fdostream, public fdistream {
|
||||
|
||||
public:
|
||||
fdstream(int fd) : fdostream(fd), fdistream(fd) {}
|
||||
};
|
||||
|
||||
class socketstream : public fdstream {
|
||||
public:
|
||||
socketstream(int fd) : fdstream(fd) {}
|
||||
|
||||
//void make_server(const std::string& address, int port);
|
||||
//void connect(const std::string& address, int port);
|
||||
};
|
||||
|
||||
struct float_80 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user