45 #ifndef INCLUDE_OLA_IO_DESCRIPTOR_H_
46 #define INCLUDE_OLA_IO_DESCRIPTOR_H_
51 #include <ola/io/IOQueue.h>
57 static const int INVALID_DESCRIPTOR = -1;
67 virtual int ReadDescriptor()
const = 0;
70 bool ValidReadDescriptor()
const {
71 return ReadDescriptor() != INVALID_DESCRIPTOR;
75 virtual void PerformRead() = 0;
85 virtual int WriteDescriptor()
const = 0;
88 bool ValidWriteDescriptor()
const {
89 return WriteDescriptor() != INVALID_DESCRIPTOR;
93 virtual void PerformWrite() = 0;
124 m_on_write = on_write;
147 int ReadDescriptor()
const {
return m_fd; }
148 int WriteDescriptor()
const {
return m_fd; }
150 bool Close() {
return true; }
163 return d1->ReadDescriptor() < d2->ReadDescriptor();
180 virtual ssize_t Send(
const uint8_t *buffer,
unsigned int size);
181 virtual ssize_t Send(
IOQueue *data);
183 virtual int Receive(uint8_t *buffer,
185 unsigned int &data_read);
187 virtual bool SetReadNonBlocking() {
188 return SetNonBlocking(ReadDescriptor());
191 virtual bool Close() = 0;
192 int DataRemaining()
const;
193 bool IsClosed()
const;
201 m_on_close = on_close;
220 static bool SetNonBlocking(
int fd);
223 virtual bool IsSocket()
const = 0;
224 bool SetNoSigPipe(
int fd);
230 OnCloseCallback *m_on_close;
241 m_fd_pair[0] = INVALID_DESCRIPTOR;
242 m_fd_pair[1] = INVALID_DESCRIPTOR;
246 int ReadDescriptor()
const {
return m_fd_pair[0]; }
247 int WriteDescriptor()
const {
return m_fd_pair[1]; }
252 bool IsSocket()
const {
return false; }
269 m_in_pair[0] = m_in_pair[1] = INVALID_DESCRIPTOR;
270 m_out_pair[0] = m_out_pair[1] = INVALID_DESCRIPTOR;
276 int ReadDescriptor()
const {
return m_in_pair[0]; }
277 int WriteDescriptor()
const {
return m_out_pair[1]; }
282 bool IsSocket()
const {
return false; }
289 m_in_pair[0] = in_pair[0];
290 m_in_pair[1] = in_pair[1];
291 m_out_pair[0] = out_pair[0];
292 m_out_pair[1] = out_pair[1];
293 m_other_end = other_end;
307 m_fd = INVALID_DESCRIPTOR;
313 int ReadDescriptor()
const {
return m_fd; }
314 int WriteDescriptor()
const {
return m_fd; }
319 bool IsSocket()
const {
return true; }
326 m_other_end = other_end;
341 int ReadDescriptor()
const {
return m_fd; }
342 int WriteDescriptor()
const {
return m_fd; }
346 bool IsSocket()
const {
return false; }
355 #endif // INCLUDE_OLA_IO_DESCRIPTOR_H_