pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.04k stars 2.11k forks source link

Overriding SocketReactor::run() is not reasonably possible #4556

Open ostkamp opened 1 month ago

ostkamp commented 1 month ago

SocketReactor has a virtual run() method, see https://github.com/pocoproject/poco/blob/ad72b25ace25da47ff3250f349d00e7ee46fb4b5/Net/include/Poco/Net/SocketReactor.h#L184

If it gets overridden by a run() method in a child class for extending its functionality, this child method has zero access to the required data of the base class (e.g. params provided to constructor, data added later through method calls etc.), since that data is completely private in base class. This also applies to several methods used in the original code of run() in the base class.

It is thus not possible to extend the functionality of the base class run() method.

To Reproduce Create a child class inheriting from SocketReactor and add a run() method which overrides. Try to copy in the code from original run() method of the base class. It won´t compile because of accessing private members and methods. Try to instantiate an object just to ensure compilation is attempted.

Expected behavior The currently private data of the base class SocketReactor should become protected so it can be accessed from overridden run() method in child class. This also applies to private methods used by the original run() method of the base class. Steps outlined in "To reproduce" should compile, link and work ok.

Logs N/A

Screenshots N/A

Please add relevant environment information:

Additional context N/A

aleks-f commented 1 month ago

If you want access to the private members from child classes, send a PR which provides it through protected member functions; we will not make the member variables protected.