Skip to content

Commit

Permalink
Split interface and base in mcp::TransportServer for easier mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
LourensVeen committed Jan 14, 2024
1 parent 6aa7a2f commit ecc7e35
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libmuscle/cpp/src/libmuscle/mcp/tcp_transport_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class TcpTransportServerWorker {
namespace libmuscle { namespace _MUSCLE_IMPL_NS { namespace mcp {

TcpTransportServer::TcpTransportServer(RequestHandler & handler)
: TransportServer(handler)
: TransportServerBase(handler)
{
pipe(control_pipe_);
thread_ = std::thread(server_thread_, this);
Expand Down
2 changes: 1 addition & 1 deletion libmuscle/cpp/src/libmuscle/mcp/tcp_transport_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace libmuscle { namespace _MUSCLE_IMPL_NS { namespace mcp {

/** A server that accepts TCP connections.
*/
class TcpTransportServer : public TransportServer {
class TcpTransportServer : public TransportServerBase {
public:
/** Create a TcpTransportServer.
*
Expand Down
2 changes: 1 addition & 1 deletion libmuscle/cpp/src/libmuscle/mcp/transport_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace libmuscle { namespace _MUSCLE_IMPL_NS {namespace mcp {

RequestHandler::~RequestHandler() {}

TransportServer::TransportServer(RequestHandler & handler)
TransportServerBase::TransportServerBase(RequestHandler & handler)
: handler_(handler)
{}

Expand Down
21 changes: 15 additions & 6 deletions libmuscle/cpp/src/libmuscle/mcp/transport_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ class RequestHandler {
*/
class TransportServer {
public:
/** Create a TransportServer.
*
* @param handler: A handler to handle requests
*/
TransportServer(RequestHandler & handler);

/** Destroy the Transport Server object
*/
virtual ~TransportServer() = default;
Expand All @@ -86,6 +80,21 @@ class TransportServer {
* then frees any other resources.
*/
virtual void close() = 0;
};


/** Base class for TransportServers.
*
* They always have a handler, so this saves some typing. This is separate from the
* interface so that we can create a mock that doesn't have the reference.
*/
class TransportServerBase : public TransportServer {
public:
/** Create a TransportServerBase.
*
* @param handler: A handler to handle requests
*/
TransportServerBase(RequestHandler & handler);

protected:
RequestHandler & handler_;
Expand Down

0 comments on commit ecc7e35

Please sign in to comment.