Skip to content

Commit

Permalink
...and the other half of the fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Oct 16, 2024
1 parent edcfbe9 commit c753a09
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
3 changes: 1 addition & 2 deletions Drv/TcpClient/TcpClientComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace Drv {
// ----------------------------------------------------------------------

TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName)
: TcpClientComponentBase(compName),
SocketComponentHelper(m_realDescriptor) {}
: TcpClientComponentBase(compName) {}

SocketIpStatus TcpClientComponentImpl::configure(const char* hostname,
const U16 port,
Expand Down
2 changes: 0 additions & 2 deletions Drv/TcpClient/TcpClientComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ class TcpClientComponentImpl : public TcpClientComponentBase, public SocketCompo

Drv::TcpClientSocket m_socket; //!< Socket implementation

Drv::SocketDescriptor m_realDescriptor; //!< Descriptor

// Member variable to store the buffer size
FwSizeType m_allocation_size;
};
Expand Down
4 changes: 2 additions & 2 deletions Drv/TcpClient/test/ut/TcpClientTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TcpClientTester ::test_with_loop(U32 iterations, bool recv_thread) {

Drv::TcpServerSocket server;
server.configure("127.0.0.1", port, 0, 100);
Drv::ServerSocketDescriptor server_fd;
Drv::SocketDescriptor server_fd;

serverStat = server.startup(server_fd);
this->component.configure("127.0.0.1", server.getListenPort(), 0, 100);
Expand Down Expand Up @@ -69,7 +69,7 @@ void TcpClientTester ::test_with_loop(U32 iterations, bool recv_thread) {
if ((Drv::SOCK_SUCCESS == status1) && (Drv::SOCK_SUCCESS == status2) &&
(this->component.isOpened())) {
// Force the sockets not to hang, if at all possible
Drv::Test::force_recv_timeout(this->component.m_realDescriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(this->component.m_descriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(server_fd.serverFd, server);
m_data_buffer.setSize(sizeof(m_data_storage));
size = Drv::Test::fill_random_buffer(m_data_buffer);
Expand Down
13 changes: 6 additions & 7 deletions Drv/TcpServer/TcpServerComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace Drv {
// ----------------------------------------------------------------------

TcpServerComponentImpl::TcpServerComponentImpl(const char* const compName)
: TcpServerComponentBase(compName),
SocketComponentHelper(this->m_realDescriptor) {}
: TcpServerComponentBase(compName) {}

SocketIpStatus TcpServerComponentImpl::configure(const char* hostname,
const U16 port,
Expand Down Expand Up @@ -73,23 +72,23 @@ void TcpServerComponentImpl::connected() {

bool TcpServerComponentImpl::isStarted() {
Os::ScopeLock scopedLock(this->m_lock);
return this->m_realDescriptor.serverFd != -1;
return this->m_descriptor.serverFd != -1;
}

SocketIpStatus TcpServerComponentImpl::startup() {
Os::ScopeLock scopedLock(this->m_lock);
Drv::SocketIpStatus status = SOCK_SUCCESS;
// Prevent multiple startup attempts
if (this->m_realDescriptor.serverFd == -1) {
status = this->m_socket.startup(this->m_realDescriptor);
if (this->m_descriptor.serverFd == -1) {
status = this->m_socket.startup(this->m_descriptor);
}
return status;
}

void TcpServerComponentImpl::terminate() {
Os::ScopeLock scopedLock(this->m_lock);
this->m_socket.terminate(this->m_realDescriptor);
this->m_realDescriptor.serverFd = -1;
this->m_socket.terminate(this->m_descriptor);
this->m_descriptor.serverFd = -1;
}

void TcpServerComponentImpl::readLoop() {
Expand Down
1 change: 0 additions & 1 deletion Drv/TcpServer/TcpServerComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class TcpServerComponentImpl : public TcpServerComponentBase, public SocketCompo
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) override;

Drv::TcpServerSocket m_socket; //!< Socket implementation
Drv::ServerSocketDescriptor m_realDescriptor; //!< Server descriptor
};

} // end namespace Drv
Expand Down
7 changes: 3 additions & 4 deletions Drv/TcpServer/test/ut/TcpServerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void TcpServerTester ::test_with_loop(U32 iterations, bool recv_thread) {
if ((Drv::SOCK_SUCCESS == status1) && (Drv::SOCK_SUCCESS == status2) &&
(this->component.isOpened())) {
// Force the sockets not to hang, if at all possible
Drv::Test::force_recv_timeout(this->component.m_realDescriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(this->component.m_descriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(client_fd.fd, client);
m_data_buffer.setSize(sizeof(m_data_storage));
size = Drv::Test::fill_random_buffer(m_data_buffer);
Expand All @@ -76,8 +76,7 @@ void TcpServerTester ::test_with_loop(U32 iterations, bool recv_thread) {
"On iteration: " << i << " and receive thread: " << recv_thread;
Drv::Test::receive_all(client, client_fd, buffer, size);
EXPECT_EQ(status2, Drv::SOCK_SUCCESS) <<
"On iteration: " << i << " and receive thread: " << recv_thread << " and errno " << errno <<
" and counter " << counter;
"On iteration: " << i << " and receive thread: " << recv_thread << " and errno " << errno;
EXPECT_EQ(size, m_data_buffer.getSize()) <<
"On iteration: " << i << " and receive thread: " << recv_thread;
Drv::Test::validate_random_buffer(m_data_buffer, buffer);
Expand All @@ -103,7 +102,7 @@ void TcpServerTester ::test_with_loop(U32 iterations, bool recv_thread) {
// Server initiates shutdown. It thus must drain its data until it receives
// a socket disconnection. Then it can safely close.
this->component.shutdown();
Drv::Test::drain(this->component.m_socket, this->component.m_realDescriptor);
Drv::Test::drain(this->component.m_socket, this->component.m_descriptor);
this->component.close();
}
// Server should have shutdown cleanly and waited for this to be shut down. It is safe
Expand Down
3 changes: 1 addition & 2 deletions Drv/Udp/UdpComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace Drv {
// ----------------------------------------------------------------------

UdpComponentImpl::UdpComponentImpl(const char* const compName)
: UdpComponentBase(compName),
SocketComponentHelper(m_realDescriptor) {}
: UdpComponentBase(compName) {}

SocketIpStatus UdpComponentImpl::configureSend(const char* hostname,
const U16 port,
Expand Down
1 change: 0 additions & 1 deletion Drv/Udp/UdpComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class UdpComponentImpl : public UdpComponentBase, public SocketComponentHelper {
* \return SEND_OK on success, SEND_RETRY when critical data should be retried and SEND_ERROR upon error
*/
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer);
Drv::SocketDescriptor m_realDescriptor; //!< UDP descriptor
Drv::UdpSocket m_socket; //!< Socket implementation
};

Expand Down
2 changes: 1 addition & 1 deletion Drv/Udp/test/ut/UdpTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
if ((Drv::SOCK_SUCCESS == status1) && (Drv::SOCK_SUCCESS == status2) &&
(this->component.isOpened())) {
// Force the sockets not to hang, if at all possible
Drv::Test::force_recv_timeout(this->component.m_realDescriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(this->component.m_descriptor.fd, this->component.getSocketHandler());
Drv::Test::force_recv_timeout(udp2_fd.fd, udp2);
m_data_buffer.setSize(sizeof(m_data_storage));
size = Drv::Test::fill_random_buffer(m_data_buffer);
Expand Down

0 comments on commit c753a09

Please sign in to comment.