Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 27, 2025
1 parent bf0d67e commit f558ae1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cpp/s2p/s2p_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ int S2p::Run(span<char*> args, bool in_process, bool log_signals)
ReadAccessToken(path(token_file));
}

if (const string &error = service_thread.Init([this](CommandContext &context) {
if (const string &error = service_thread.Init(port, [this](CommandContext &context) {
return ExecuteCommand(context);
}, port, s2p_logger); !error.empty()) {
}, s2p_logger); !error.empty()) {
cerr << "Error: " << error << '\n';
CleanUp();
return EXIT_FAILURE;
Expand Down
9 changes: 2 additions & 7 deletions cpp/s2p/s2p_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@

using namespace s2p_util;

string S2pThread::Init(const callback &cb, int port, shared_ptr<logger> logger)
string S2pThread::Init(int port, const callback &cb, shared_ptr<logger> logger)
{
if (const string &error = server.Init(port); !error.empty()) {
return error;
}

exec = cb;

s2p_logger = logger;

return "";
return server.Init(port);
}

void S2pThread::Start()
Expand Down
2 changes: 1 addition & 1 deletion cpp/s2p/s2p_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class S2pThread

public:

string Init(const callback&, int, shared_ptr<logger> logger);
string Init(int, const callback&, shared_ptr<logger> logger);
void Start();
void Stop();
bool IsRunning() const;
Expand Down
16 changes: 8 additions & 8 deletions cpp/test/s2p_thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2022-2023 Uwe Seimet
// Copyright (C) 2022-2025 Uwe Seimet
//
// These tests only test up the point where a network connection is required.
//
Expand Down Expand Up @@ -43,10 +43,10 @@ TEST(S2pThreadTest, Init)
{
S2pThread service_thread;

EXPECT_FALSE(service_thread.Init(nullptr, 65536, default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(nullptr, 0,default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(nullptr, -1, default_logger()).empty()) << "Illegal port number";
EXPECT_TRUE(service_thread.Init(nullptr, 9999, default_logger()).empty())
EXPECT_FALSE(service_thread.Init(65536,nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(0, nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(-1, nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_TRUE(service_thread.Init(9999, nullptr,default_logger()).empty())
<< "Port 9999 is expected not to be in use for this test";
service_thread.Stop();
}
Expand All @@ -55,7 +55,7 @@ TEST(S2pThreadTest, IsRunning)
{
S2pThread service_thread;
EXPECT_FALSE(service_thread.IsRunning());
EXPECT_TRUE(service_thread.Init(nullptr, 9999, default_logger()).empty())
EXPECT_TRUE(service_thread.Init(9999, nullptr, default_logger()).empty())
<< "Port 9999 is expected not to be in use for this test";
EXPECT_FALSE(service_thread.IsRunning());

Expand All @@ -80,15 +80,15 @@ TEST(S2pThreadTest, Execute)
close(fd);

S2pThread service_thread;
service_thread.Init([](const CommandContext &context) {
service_thread.Init(9999, [](const CommandContext &context) {
if (context.GetCommand().operation() != PbOperation::NO_OPERATION) {
throw IoException("error");
}

PbResult result;
result.set_status(true);
return context.WriteResult(result);
}, 9999, default_logger());
}, default_logger());

service_thread.Start();

Expand Down

0 comments on commit f558ae1

Please sign in to comment.