libUTL++
FDstream.h
1 #pragma once
2 
4 
5 #include <libutl/Stream.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
33 
35 class FDstream : public Stream
36 {
37  friend class BufferedFDstream;
40 
41 public:
47  FDstream(int fd, uint_t mode);
48 
50  virtual void close();
51 
53  void
55  {
56  _fd = -1;
57  clear();
58  }
59 
61  int
62  fd() const
63  {
64  return _fd;
65  }
66 
67 #if UTL_HOST_OS != UTL_OS_MINGW
68 
69  bool isSocket() const;
70 #endif
71 
73  bool isTTY() const;
74 
80  virtual void setFD(int fd, uint_t mode = io_rd | io_wr);
81 
82  virtual size_t read(byte_t* array, size_t maxBytes, size_t minBytes = size_t_max);
83 
84  virtual void write(const byte_t* array, size_t num);
85 
86 #if UTL_HOST_OS != UTL_OS_MINGW
87 
88  bool
89  blockingIO() const
90  {
91  return !getFlag(flg_nonBlocking);
92  }
93 
95  void setBlockingIO(bool v);
96 
102  bool blockRead(uint32_t usec = 0);
103 
109  bool blockWrite(uint32_t usec = 0);
110 #endif
111 protected:
113  virtual void clear();
114 
116  virtual void setModes();
117 
118 protected:
119  int _fd;
120 
121 private:
122  enum flg_t
123  {
124  flg_nonBlocking = 4
125  };
126 
127 private:
128  void
129  init()
130  {
131  _fd = -1;
132  }
133  void
134  deInit()
135  {
136  close();
137  }
138 };
139 
141 
142 UTL_NS_END;
void deInit()
De-initialize UTL++.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
unsigned char byte_t
Unsigned character.
Definition: types.h:31
const size_t size_t_max
Maximum size_t value.
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
write
Definition: util.h:59
read
Definition: util.h:58
int fd() const
Get the associated file descriptor.
Definition: FDstream.h:62
bool blockingIO() const
Is blocking I/O enabled on the file descriptor?
Definition: FDstream.h:89
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
#define UTL_CLASS_NO_COPY
Declare that a class cannot do copy().
Definition: macros.h:358
Stream with file descriptor.
Definition: FDstream.h:35
void detach()
Detach from the file.
Definition: FDstream.h:54
void init()
Initialize UTL++.
Buffered stream with file descriptor.