Major changes to socket scheduling in EPoll.
This commit is contained in:
1 parent
790906a6dc
commit
a5a51f8aae
512 files changed
+22663
-2121
No files matched your search
@@ -34,15 +34,20 @@ namespace core {
|
||||
public:
|
||||
|
||||
Socket(EPoll &ePoll);
|
||||
Socket(EPoll &ePoll, std::string text);
|
||||
~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 without a virtual destructor.
|
||||
///
|
||||
|
||||
void shutdown();
|
||||
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.
|
||||
/// on the EPoll controller. setDescriptor will invoke the onRegister() event.
|
||||
///
|
||||
|
||||
void setDescriptor(int descriptor); ///<Set the descriptor for the socket.
|
||||
@@ -68,13 +73,13 @@ namespace core {
|
||||
/// simulated.
|
||||
///
|
||||
|
||||
void eventReceived(struct epoll_event event); ///< Parse epoll event and call specified callbacks.
|
||||
bool eventReceived(struct epoll_event event); ///< Parse epoll event and call specified callbacks.
|
||||
|
||||
///
|
||||
/// Write data to the socket.
|
||||
///
|
||||
|
||||
void write(std::string data);
|
||||
int write(std::string data);
|
||||
void write(char *buffer, int length);
|
||||
|
||||
void output(std::stringstream &out);
|
||||
@@ -98,7 +103,9 @@ namespace core {
|
||||
|
||||
virtual void onUnregister(); ///< Called when the socket has finished unregistering for the epoll processing.
|
||||
|
||||
void enable(bool mode); ///< Enable the socket to read or write based upon buffer.
|
||||
bool needsToWrite();
|
||||
|
||||
bool active = false;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -130,8 +137,10 @@ namespace core {
|
||||
/// @param data the data that has been received from the socket.
|
||||
///
|
||||
|
||||
virtual void onDataReceived(std::string data) = 0; ///< Called when data is received from the socket.
|
||||
|
||||
virtual void onDataReceived(std::string data); ///< Called when data is received from the socket.
|
||||
|
||||
virtual void onDataReceived(char *buffer, int len);
|
||||
|
||||
///
|
||||
/// receiveData will read the data from the socket and place it in the socket buffer.
|
||||
/// TLS layer overrides this to be able to read from SSL.
|
||||
@@ -140,24 +149,14 @@ namespace core {
|
||||
virtual void receiveData(char *buffer, int bufferLength);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
std::string text;
|
||||
int descriptor = -1;
|
||||
std::mutex lock;
|
||||
std::mutex socketLock;
|
||||
bool readHangup = false;
|
||||
|
||||
struct epoll_event event; // Event selection construction structure.
|
||||
|
||||
//--------------------------------------------------
|
||||
// These are used to schedule the socket activity.
|
||||
//--------------------------------------------------
|
||||
|
||||
void setRead(); ///< Queue a request to read from this socket.
|
||||
void setWrite(); ///< Queue a request to write to this socket.
|
||||
void setReadWrite();
|
||||
void resetRead();
|
||||
void resetWrite();;
|
||||
void resetReadWrite();
|
||||
void clear();
|
||||
// struct epoll_event event; // Event selection construction structure.
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// the writeSocket is called when epoll has received a write request for a socket.
|
||||
@@ -181,9 +180,7 @@ namespace core {
|
||||
// const char * const current_;
|
||||
|
||||
std::queue<std::string> fifo;
|
||||
|
||||
bool active = false;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user