-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef MS_SCTP_USRSCTP_CHECKER_HPP | ||
#define MS_SCTP_USRSCTP_CHECKER_HPP | ||
|
||
#include "common.hpp" | ||
#include "handles/TimerHandle.hpp" | ||
#include <uv.h> | ||
|
||
namespace SCTP | ||
{ | ||
class UsrSctpChecker : public TimerHandle::Listener | ||
{ | ||
public: | ||
UsrSctpChecker(); | ||
~UsrSctpChecker() override; | ||
|
||
public: | ||
void Start(); | ||
void Stop(); | ||
|
||
/* Pure virtual methods inherited from TimerHandle::Listener. */ | ||
public: | ||
void OnTimer(TimerHandle* timer) override; | ||
|
||
private: | ||
TimerHandle* timer{ nullptr }; | ||
uint64_t lastCalledAtMs{ 0u }; | ||
}; | ||
} // namespace SCTP | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* NOTE: The UsrSctpChecker singleton must run in its own thread so it cannot | ||
* use Logger.hpp since Logger communicates via UnixSocket with Node or Rust | ||
* and there must be a single thread writing into that socket in worker side. | ||
*/ | ||
|
||
#include "SCTP/UsrSctpChecker.hpp" | ||
#include "DepLibUV.hpp" | ||
#include <usrsctp.h> | ||
|
||
namespace SCTP | ||
{ | ||
/* Static. */ | ||
|
||
static constexpr size_t CheckerInterval{ 10u }; // In ms. | ||
|
||
/* UsrSctpChecker instance methods. */ | ||
|
||
UsrSctpChecker::UsrSctpChecker() | ||
{ | ||
this->timer = new TimerHandle(this); | ||
|
||
DepLibUV::RunLoop(); | ||
} | ||
|
||
UsrSctpChecker::~UsrSctpChecker() | ||
{ | ||
delete this->timer; | ||
} | ||
|
||
void UsrSctpChecker::Start() | ||
{ | ||
this->lastCalledAtMs = 0u; | ||
|
||
this->timer->Start(CheckerInterval, CheckerInterval); | ||
} | ||
|
||
void UsrSctpChecker::Stop() | ||
{ | ||
this->lastCalledAtMs = 0u; | ||
|
||
this->timer->Stop(); | ||
} | ||
|
||
void UsrSctpChecker::OnTimer(TimerHandle* /*timer*/) | ||
{ | ||
auto nowMs = DepLibUV::GetTimeMs(); | ||
const int elapsedMs = this->lastCalledAtMs ? static_cast<int>(nowMs - this->lastCalledAtMs) : 0; | ||
|
||
// TODO: This must run in the worker thread obviously. How3ver this is not easy | ||
// at all. Note that usrsctp_handle_timers() may trigger many calls to the | ||
// usrsctp onSendSctpData() callback, but each of those call may be intended | ||
// for a SctpAssociation in whatever other worker/thread, so we cannot just | ||
// try to group all them together. | ||
// #ifdef MS_LIBURING_SUPPORTED | ||
// Activate liburing usage. | ||
// 'usrsctp_handle_timers()' will synchronously call the send/recv | ||
// callbacks for the pending data. If there are multiple messages to be | ||
// sent over the network then we will send those messages within a single | ||
// system call. | ||
// DepLibUring::SetActive(); | ||
// #endif | ||
|
||
usrsctp_handle_timers(elapsedMs); | ||
|
||
// TODO: This must run in the worker thread obviously. | ||
// #ifdef MS_LIBURING_SUPPORTED | ||
// Submit all prepared submission entries. | ||
// DepLibUring::Submit(); | ||
// #endif | ||
|
||
this->lastCalledAtMs = nowMs; | ||
} | ||
} // namespace SCTP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters