#ifndef __Socket_h__ #define __Socket_h__ #include "ZString.h" #include #include #include namespace core { class EPoll; /// /// Socket /// /// The core component to managing a socket. /// /// Hooks into the EPoll through the registration and unregistration process and provides a /// communication socket of the specified protocol type. This object provides for all receiving /// data threading through use of the EPoll object and also provides buffering for output data /// requests to the socket. /// /// A program using a socket object can request to open a socket (network or device) and /// communicate through the streambuffer interface of the socket object. /// /// The socket side of the Socket accepts EPOLLIN event and will maintain the data in a buffer /// for the stream readers to read. A onDataReceived event is then sent with the data received in /// the buffer that can be read through the stream. Only sockets that send events to epoll can be /// used with this object. /// /// When writing to the stream the data is written into a buffer and a EPOLLOUT is scheduled. Upon /// receiving the EPOLLOUT event then the buffer is written to the socket output. /// class Socket { public: /// /// Constructor /// /// @param ePoll The EPoll socket descriptor. /// @param text A title for this socket. /// Socket(EPoll &ePoll, std::string text = ""); /// /// Destructor /// virtual ~Socket(); /// /// Use the shutdown() method to terminate the socket connection and remove resources. /// This method is provided to ensure that all destructors are called for all inherited /// objects with a virtual destructor. /// void shutdown(std::string text = "unknown"); /// /// setDescriptor establishes the file descriptor for the socket and registers the socket /// on the EPoll controller. setDescriptor will invoke the onRegister() event. /// void setDescriptor(int descriptor); /// fifo; void resetSocket(); std::mutex lock; }; } #endif