21 #ifndef INCLUDE_OLA_IO_DESCRIPTOR_H_
22 #define INCLUDE_OLA_IO_DESCRIPTOR_H_
28 #include <ola/io/IOQueue.h>
79 GENERIC_DESCRIPTOR = 0,
85 struct DescriptorHandle {
92 DescriptorType m_type;
96 uint8_t* m_async_data;
98 uint32_t* m_async_data_size;
103 bool AllocAsyncBuffer();
104 void FreeAsyncBuffer();
106 bool IsValid()
const;
109 void* ToHandle(
const DescriptorHandle &handle);
111 static DescriptorHandle INVALID_DESCRIPTOR;
112 static const uint32_t ASYNC_DATA_BUFFER_SIZE = 1024;
113 bool operator!=(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
114 bool operator==(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
115 bool operator<(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
116 std::ostream&
operator<<(std::ostream &stream,
const DescriptorHandle &data);
118 typedef int DescriptorHandle;
119 static DescriptorHandle INVALID_DESCRIPTOR = -1;
131 int ToFD(
const DescriptorHandle& handle);
232 m_on_write = on_write;
260 DescriptorHandle m_handle;
299 virtual ssize_t
Send(
const uint8_t *buffer,
unsigned int size);
322 virtual int Receive(uint8_t *buffer,
324 unsigned int &data_read);
336 virtual bool Close() = 0;
357 m_on_close = on_close;
381 virtual bool IsSocket()
const = 0;
389 OnCloseCallback *m_on_close;
424 bool IsSocket()
const {
return false; }
427 DescriptorHandle m_handle_pair[2];
430 DISALLOW_COPY_AND_ASSIGN(LoopbackDescriptor);
471 bool IsSocket()
const {
return false; }
474 DescriptorHandle m_in_pair[2];
475 DescriptorHandle m_out_pair[2];
476 PipeDescriptor *m_other_end;
478 PipeDescriptor(DescriptorHandle in_pair[2],
479 DescriptorHandle out_pair[2],
480 PipeDescriptor *other_end);
483 DISALLOW_COPY_AND_ASSIGN(PipeDescriptor);
493 m_handle = INVALID_DESCRIPTOR;
525 bool IsSocket()
const {
return true; }
528 DescriptorHandle m_handle;
529 UnixSocket *m_other_end;
530 UnixSocket(
int socket, UnixSocket *other_end);
532 DISALLOW_COPY_AND_ASSIGN(UnixSocket);
556 bool IsSocket()
const {
return false; }
559 DescriptorHandle m_handle;
567 #endif // INCLUDE_OLA_IO_DESCRIPTOR_H_