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; }
162 return d1->ReadDescriptor() < d2->ReadDescriptor();
179 virtual ssize_t Send(
const uint8_t *buffer,
unsigned int size);
180 virtual ssize_t Send(
IOQueue *data);
182 virtual int Receive(uint8_t *buffer,
184 unsigned int &data_read);
186 virtual bool SetReadNonBlocking() {
187 return SetNonBlocking(ReadDescriptor());
190 virtual bool Close() = 0;
191 int DataRemaining()
const;
192 bool IsClosed()
const;
200 m_on_close = on_close;
219 static bool SetNonBlocking(
int fd);
222 virtual bool IsSocket()
const = 0;
223 bool SetNoSigPipe(
int fd);
229 OnCloseCallback *m_on_close;
240 m_fd_pair[0] = INVALID_DESCRIPTOR;
241 m_fd_pair[1] = INVALID_DESCRIPTOR;
245 int ReadDescriptor()
const {
return m_fd_pair[0]; }
246 int WriteDescriptor()
const {
return m_fd_pair[1]; }
251 bool IsSocket()
const {
return false; }
268 m_in_pair[0] = m_in_pair[1] = INVALID_DESCRIPTOR;
269 m_out_pair[0] = m_out_pair[1] = INVALID_DESCRIPTOR;
275 int ReadDescriptor()
const {
return m_in_pair[0]; }
276 int WriteDescriptor()
const {
return m_out_pair[1]; }
281 bool IsSocket()
const {
return false; }
288 m_in_pair[0] = in_pair[0];
289 m_in_pair[1] = in_pair[1];
290 m_out_pair[0] = out_pair[0];
291 m_out_pair[1] = out_pair[1];
292 m_other_end = other_end;
306 m_fd = INVALID_DESCRIPTOR;
312 int ReadDescriptor()
const {
return m_fd; }
313 int WriteDescriptor()
const {
return m_fd; }
318 bool IsSocket()
const {
return true; }
325 m_other_end = other_end;
340 int ReadDescriptor()
const {
return m_fd; }
341 int WriteDescriptor()
const {
return m_fd; }
345 bool IsSocket()
const {
return false; }
354 #endif // INCLUDE_OLA_IO_DESCRIPTOR_H_