easy-socket icon indicating copy to clipboard operation
easy-socket copied to clipboard

upgrade EasySocket

Open flufy3d opened this issue 2 years ago • 0 comments

Improvements to the Original Library

Below is a summary of the enhancements made to the original library as indicated in the patch file:

  1. Introduction of stopFlag and listeningSocket

    • A std::atomic<bool> stopFlag has been introduced to facilitate the stopping of the socket listening process in a thread-safe manner.
    • A SOCKET listeningSocket has been introduced to hold the socket that is currently listening for incoming connections.
  2. Enhanced Error Handling

    • The error handling has been improved to better manage socket errors and data size exceptions during the socket communication process.
  3. Improved Socket Closure

    • The closeAllConnections method has been introduced to close all active connections and clear the respective maps holding the client and server sockets.
    • The sockQuit function is called within the closeAllConnections method to clean up the socket library after closing all connections.
  4. Improved Socket Sending and Receiving

    • The socketSend method has been updated to check both the client and server socket maps to find the appropriate socket associated with the channel name before sending data.
    • The socketReceive method has been introduced to facilitate the receiving of data from a socket associated with a given channel name, with appropriate error handling and buffer management.
  5. Refined Socket Listening

    • The socketListen method has been refined to incorporate the stopFlag to allow for the graceful stopping of the listening process.
    • The method now handles the SOCKET_ERROR more gracefully, avoiding the throwing of exceptions in certain cases and instead opting for a loop continuation, allowing for more robust server operation.
  6. Better Management of Client and Server Sockets

    • The client and server sockets are now stored in separate unordered maps, allowing for better organization and management of the sockets.
    • The socketSend and socketReceive methods have been updated to check both the client and server socket maps to find the correct socket associated with a given channel name, improving the flexibility of the socket communication process.
  7. Introduction of New Exceptions

    • A new exception, masesk::invalid_socket_exception, has been introduced to handle cases where an invalid socket is encountered, enhancing the robustness of the error handling process.
  8. Code Cleanup and Organization

    • The code has been reorganized and cleaned up to improve readability and maintainability.
    • Redundant code has been removed, and the structure of the methods has been optimized for better performance and efficiency.

flufy3d avatar Sep 20 '23 13:09 flufy3d