Skip to content

Commit

Permalink
Propagate PSH flag up to the Client delegate (#90)
Browse files Browse the repository at this point in the history
* Propagate PSH flag to up to the Client delegate

* Minor linting fixes
  • Loading branch information
xguerin authored Dec 8, 2023
1 parent 549054c commit be26e4b
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Checks: '-*,bugprone-*,-bugprone-easily-swappable-parameters,-bugprone-narrowing-conversions,-bugprone-reserved-identifier,modernize-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-modernize-use-default-member-init,-modernize-avoid-c-arrays,performance-*,readability-braces-around-statements'
Checks: '-*,bugprone-*,-bugprone-easily-swappable-parameters,-bugprone-narrowing-conversions,-bugprone-reserved-identifier,modernize-*,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-modernize-use-default-member-init,-modernize-avoid-c-arrays,performance-*,-performance-avoid-endl,readability-braces-around-statements'
WarningsAsErrors: '-*,bugprone-*,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,-bugprone-reserved-identifier'
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,12 @@ if (LINUX)
list(FILTER SOURCES EXCLUDE REGEX ".*tap.*")
endif (LINUX)

if (NOT LibDPDK_FOUND)
list(FILTER SOURCES EXCLUDE REGEX ".*ena.*")
endif (NOT LibDPDK_FOUND)

if (NOT LibIBVerbs_FOUND)
list(FILTER SOURCES EXCLUDE REGEX ".*ofed.*")
list(FILTER SOURCES EXCLUDE REGEX ".*uspace.*")
endif (NOT LibIBVerbs_FOUND)

foreach (SOURCE ${SOURCES})
Expand Down
8 changes: 4 additions & 4 deletions include/tulips/api/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ClientDelegate : public Client::Delegate

Action onNewData(Client::ID const& id, void* const cookie,
const uint8_t* const rdat, const uint32_t rlen,
const Timestamp ts, const uint32_t savl, uint8_t* const sdat,
uint32_t& slen) override;
const bool pushed, const Timestamp ts, const uint32_t savl,
uint8_t* const sdat, uint32_t& slen) override;

void onClosed(Client::ID const& id, void* const cookie,
const Timestamp ts) override;
Expand All @@ -40,8 +40,8 @@ class ServerDelegate : public Server::Delegate

Action onNewData(Server::ID const& id, void* const cookie,
const uint8_t* const rdat, const uint32_t rlen,
const Timestamp ts, const uint32_t savl, uint8_t* const sdat,
uint32_t& slen) override;
const bool pushed, const Timestamp ts, const uint32_t savl,
uint8_t* const sdat, uint32_t& slen) override;

void onClosed(Server::ID const& id, void* const cookie,
const Timestamp ts) override;
Expand Down
6 changes: 4 additions & 2 deletions include/tulips/api/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct Delegate
* @param cookie the connection's user-defined state.
* @param rdat the received data.
* @param rlen the length of the received data.
* @param pushed the incoming packet was PSH'd
* @param ts the timestamp of the operation.
* @param savl the amount of data available in the response frame.
* @param sdat a pointer to the response area in the frame.
Expand All @@ -73,8 +74,9 @@ struct Delegate
*/
virtual Action onNewData(ID const& id, void* const cookie,
const uint8_t* const rdat, const uint32_t rlen,
const Timestamp ts, const uint32_t savl,
uint8_t* const sdat, uint32_t& slen) = 0;
const bool pushed, const Timestamp ts,
const uint32_t savl, uint8_t* const sdat,
uint32_t& slen) = 0;

/*
* Callback when a connection is closed.
Expand Down
6 changes: 3 additions & 3 deletions include/tulips/ssl/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <tulips/api/Interface.h>
#include <tulips/ssl/Connection.h>
#include <tulips/ssl/Protocol.h>
#include <vector>

namespace tulips::ssl {

Expand Down Expand Up @@ -128,8 +127,9 @@ class Client final
uint32_t& slen) override;

Action onNewData(ID const& id, void* const cookie, const uint8_t* const data,
const uint32_t len, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen) override;
const uint32_t len, const bool pushed, const Timestamp ts,
const uint32_t alen, uint8_t* const sdata,
uint32_t& slen) override;

void onClosed(ID const& id, void* const cookie, const Timestamp ts) override;

Expand Down
4 changes: 2 additions & 2 deletions include/tulips/ssl/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Connection
*/
Action onNewData(system::Logger& log, ID const& id, Delegate& delegate,
const uint8_t* const rdat, const uint32_t rlen,
const system::Clock::Value ts, const uint32_t savl,
uint8_t* const sdat, uint32_t& slen);
const bool pushed, const system::Clock::Value ts,
const uint32_t savl, uint8_t* const sdat, uint32_t& slen);

/**
* Return the connection's state.
Expand Down
5 changes: 3 additions & 2 deletions include/tulips/ssl/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class Server
uint32_t& slen) override;

Action onNewData(ID const& id, void* const cookie, const uint8_t* const data,
const uint32_t len, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen) override;
const uint32_t len, const bool pushed, const Timestamp ts,
const uint32_t alen, uint8_t* const sdata,
uint32_t& slen) override;

void onClosed(ID const& id, void* const cookie, const Timestamp ts) override;

Expand Down
4 changes: 2 additions & 2 deletions src/api/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ Client::onNewData(stack::tcpv4::Connection& c, const uint8_t* const data,
const uint32_t len, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen)
{
return m_delegate.onNewData(c.id(), c.cookie(), data, len, ts, alen, sdata,
slen);
return m_delegate.onNewData(c.id(), c.cookie(), data, len,
c.isNewDataPushed(), ts, alen, sdata, slen);
}

}
8 changes: 4 additions & 4 deletions src/api/Defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Action
ClientDelegate::onNewData(UNUSED Client::ID const& id,
UNUSED void* const cookie,
UNUSED const uint8_t* const rdat,
UNUSED const uint32_t rlen, UNUSED const Timestamp ts,
UNUSED const uint32_t savl,
UNUSED const uint32_t rlen, UNUSED const bool pushed,
UNUSED const Timestamp ts, UNUSED const uint32_t savl,
UNUSED uint8_t* const sdat, UNUSED uint32_t& slen)
{
return Action::Continue;
Expand Down Expand Up @@ -55,8 +55,8 @@ Action
ServerDelegate::onNewData(UNUSED Server::ID const& id,
UNUSED void* const cookie,
UNUSED const uint8_t* const rdat,
UNUSED const uint32_t rlen, UNUSED const Timestamp ts,
UNUSED const uint32_t savl,
UNUSED const uint32_t rlen, UNUSED const bool pushed,
UNUSED const Timestamp ts, UNUSED const uint32_t savl,
UNUSED uint8_t* const sdat, UNUSED uint32_t& slen)
{
return Action::Continue;
Expand Down
4 changes: 2 additions & 2 deletions src/api/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Server::onNewData(stack::tcpv4::Connection& c, const uint8_t* const data,
const uint32_t len, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen)
{
return m_delegate.onNewData(c.id(), c.cookie(), data, len, ts, alen, sdata,
slen);
return m_delegate.onNewData(c.id(), c.cookie(), data, len,
c.isNewDataPushed(), ts, alen, sdata, slen);
}

}
6 changes: 3 additions & 3 deletions src/apps/TCPLatency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ class Delegate : public api::defaults::ServerDelegate

Action onNewData(UNUSED tulips::api::Server::ID const& id,
UNUSED void* const cookie, const uint8_t* const data,
const uint32_t len, UNUSED const Timestamp ts,
UNUSED const uint32_t alen, UNUSED uint8_t* const sdata,
UNUSED uint32_t& slen) override
const uint32_t len, UNUSED const bool pushed,
UNUSED const Timestamp ts, UNUSED const uint32_t alen,
UNUSED uint8_t* const sdata, UNUSED uint32_t& slen) override
{
size_t const& header = *reinterpret_cast<const size_t*>(data);
if (header != m_next) {
Expand Down
7 changes: 4 additions & 3 deletions src/ssl/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ Client::onAcked(ID const& id, [[maybe_unused]] void* const cookie,
Action
Client::onNewData(ID const& id, [[maybe_unused]] void* const cookie,
const uint8_t* const data, const uint32_t len,
const Timestamp ts, const uint32_t alen, uint8_t* const sdata,
uint32_t& slen)
const bool pushed, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen)
{
/*
* Grab the connection.
Expand All @@ -413,7 +413,8 @@ Client::onNewData(ID const& id, [[maybe_unused]] void* const cookie,
/*
* Write the data in the input BIO.
*/
return c.onNewData(m_log, id, m_delegate, data, len, ts, alen, sdata, slen);
return c.onNewData(m_log, id, m_delegate, data, len, pushed, ts, alen, sdata,
slen);
}

void
Expand Down
9 changes: 5 additions & 4 deletions src/ssl/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ errorToString(const int err)
return "SSL_ERROR_WANT_X509_LOOKUP";
case SSL_ERROR_SYSCALL:
return "SSL_ERROR_SYSCALL";
case SSL_ERROR_SSL: {
default: {
char buffer[1024];
ERR_error_string_n(ERR_peek_error(), buffer, 1024);
return { buffer };
Expand Down Expand Up @@ -283,8 +283,8 @@ Action
Connection::onNewData(system::Logger& log, ID const& id,
api::interface::Delegate<ID>& delegate,
const uint8_t* const rdat, const uint32_t rlen,
const system::Clock::Value ts, const uint32_t savl,
uint8_t* const sdat, uint32_t& slen)
const bool pushed, const system::Clock::Value ts,
const uint32_t savl, uint8_t* const sdat, uint32_t& slen)
{
/*
* Write the data in the input BIO.
Expand Down Expand Up @@ -443,7 +443,8 @@ Connection::onNewData(system::Logger& log, ID const& id,
*/
uint32_t r = 0;
uint32_t w = savl - acc;
auto act = delegate.onNewData(id, m_cookie, m_rdbf, ret, ts, w, out, r);
auto act =
delegate.onNewData(id, m_cookie, m_rdbf, ret, pushed, ts, w, out, r);
/*
* Bail out if the connection is not longer ready.
*/
Expand Down
7 changes: 4 additions & 3 deletions src/ssl/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ Server::onAcked(ID const& id, [[maybe_unused]] void* const cookie,
Action
Server::onNewData(ID const& id, [[maybe_unused]] void* const cookie,
const uint8_t* const data, const uint32_t len,
const Timestamp ts, const uint32_t alen, uint8_t* const sdata,
uint32_t& slen)
const bool pushed, const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen)
{
/*
* Grab the connection.
Expand All @@ -184,7 +184,8 @@ Server::onNewData(ID const& id, [[maybe_unused]] void* const cookie,
/*
* Write the data in the input BIO.
*/
return c.onNewData(m_log, id, m_delegate, data, len, ts, alen, sdata, slen);
return c.onNewData(m_log, id, m_delegate, data, len, pushed, ts, alen, sdata,
slen);
}

void
Expand Down
6 changes: 6 additions & 0 deletions src/stack/arp/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ Processor::process(const uint16_t len, const uint8_t* const data,
update(INARP->sipaddr, INARP->shwaddr);
break;
}
/*
* Ignore any other value.
*/
default: {
break;
}
}
/*
* Return our status
Expand Down
3 changes: 2 additions & 1 deletion src/stack/tcpv4/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ Processor::process(Connection& e, const uint16_t len, const uint8_t* const data,
/*
* Unhandled cases.
*/
case Connection::CLOSED: {
default: {
break;
}
}
Expand All @@ -1244,4 +1244,5 @@ Processor::process(Connection& e, const uint16_t len, const uint8_t* const data,
*/
return Status::Ok;
}

}
5 changes: 3 additions & 2 deletions tests/api/one_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class ServerDelegate : public api::defaults::ServerDelegate

Action onNewData(UNUSED api::Server::ID const& id, UNUSED void* const cookie,
UNUSED const uint8_t* const data, UNUSED const uint32_t len,
UNUSED const Timestamp ts, UNUSED const uint32_t alen,
UNUSED uint8_t* const sdata, UNUSED uint32_t& slen) override
UNUSED const bool pushed, UNUSED const Timestamp ts,
UNUSED const uint32_t alen, UNUSED uint8_t* const sdata,
UNUSED uint32_t& slen) override
{
return m_action;
}
Expand Down
8 changes: 5 additions & 3 deletions tests/api/two_clients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ClientDelegate : public api::defaults::ClientDelegate
tulips::Action onNewData(UNUSED api::Client::ID const& id,
UNUSED void* const cookie,
UNUSED const uint8_t* const data,
UNUSED const uint32_t len, UNUSED const Timestamp ts,
UNUSED const uint32_t len, UNUSED const bool pushed,
UNUSED const Timestamp ts,
UNUSED const uint32_t alen,
UNUSED uint8_t* const sdata,
UNUSED uint32_t& slen) override
Expand Down Expand Up @@ -52,8 +53,9 @@ class ServerDelegate : public api::defaults::ServerDelegate

Action onNewData(UNUSED api::Server::ID const& id, UNUSED void* const cookie,
const uint8_t* const data, const uint32_t len,
UNUSED const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen) override
UNUSED const bool pushed, UNUSED const Timestamp ts,
const uint32_t alen, uint8_t* const sdata,
uint32_t& slen) override
{
if (m_send_back && alen >= len) {
memcpy(sdata, data, len);
Expand Down
3 changes: 2 additions & 1 deletion tests/ssl/one_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ServerDelegate : public api::defaults::ServerDelegate

tulips::Action onNewData(UNUSED api::Client::ID const& id,
UNUSED void* const cookie, const uint8_t* const data,
UNUSED const uint32_t len, UNUSED const Timestamp ts,
UNUSED const uint32_t len, UNUSED const bool pushed,
UNUSED const Timestamp ts,
UNUSED const uint32_t alen,
UNUSED uint8_t* const sdata,
UNUSED uint32_t& slen) override
Expand Down
8 changes: 5 additions & 3 deletions tests/ssl/two_clients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ClientDelegate : public api::defaults::ClientDelegate
tulips::Action onNewData(UNUSED api::Client::ID const& id,
UNUSED void* const cookie,
UNUSED const uint8_t* const data,
UNUSED const uint32_t len, UNUSED const Timestamp ts,
UNUSED const uint32_t len, UNUSED const bool pushed,
UNUSED const Timestamp ts,
UNUSED const uint32_t alen,
UNUSED uint8_t* const sdata,
UNUSED uint32_t& slen) override
Expand Down Expand Up @@ -52,8 +53,9 @@ class ServerDelegate : public api::defaults::ServerDelegate

Action onNewData(UNUSED api::Server::ID const& id, UNUSED void* const cookie,
const uint8_t* const data, const uint32_t len,
UNUSED const Timestamp ts, const uint32_t alen,
uint8_t* const sdata, uint32_t& slen) override
UNUSED const bool pushed, UNUSED const Timestamp ts,
const uint32_t alen, uint8_t* const sdata,
uint32_t& slen) override
{
if (m_send_back && alen >= len) {
memcpy(sdata, data, len);
Expand Down
4 changes: 2 additions & 2 deletions tests/tcp/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Client : public tcpv4::EventHandler
m_out.open(path);
}

~Client() override { m_out.close(); }
~Client() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(UNUSED tcpv4::Connection& c,
UNUSED const Timestamp ts) override
Expand Down Expand Up @@ -94,7 +94,7 @@ class Server : public tcpv4::EventHandler
m_out.open(path);
}

~Server() override { m_out.close(); }
~Server() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(tcpv4::Connection& c, UNUSED const Timestamp ts) override
{
Expand Down
4 changes: 2 additions & 2 deletions tests/tcp/keepalive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Client : public tcpv4::EventHandler
m_out.open(path);
}

~Client() override { m_out.close(); }
~Client() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(UNUSED tcpv4::Connection& c,
UNUSED const Timestamp ts) override
Expand Down Expand Up @@ -96,7 +96,7 @@ class Server : public tcpv4::EventHandler
m_out.open(path);
}

~Server() override { m_out.close(); }
~Server() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(tcpv4::Connection& c, UNUSED const Timestamp ts) override
{
Expand Down
4 changes: 2 additions & 2 deletions tests/tcp/nagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Client : public tcpv4::EventHandler
m_out.open(path);
}

~Client() override { m_out.close(); }
~Client() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(UNUSED tcpv4::Connection& c,
UNUSED const Timestamp ts) override
Expand Down Expand Up @@ -95,7 +95,7 @@ class Server : public tcpv4::EventHandler
m_out.open(path);
}

~Server() override { m_out.close(); }
~Server() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(tcpv4::Connection& c, UNUSED const Timestamp ts) override
{
Expand Down
4 changes: 2 additions & 2 deletions tests/tcp/nodelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Client : public tcpv4::EventHandler
m_out.open(path);
}

~Client() override { m_out.close(); }
~Client() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(tcpv4::Connection& c, UNUSED const Timestamp ts) override
{
Expand Down Expand Up @@ -94,7 +94,7 @@ class Server : public tcpv4::EventHandler
m_out.open(path);
}

~Server() override { m_out.close(); }
~Server() override { m_out.close(); } // NOLINT(bugprone-exception-escape)

void onConnected(tcpv4::Connection& c, UNUSED const Timestamp ts) override
{
Expand Down
Loading

0 comments on commit be26e4b

Please sign in to comment.