mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-30 17:36:16 +02:00
replace gettimeofday with chronos::systemtimeofday
This commit is contained in:
parent
b0f1bee219
commit
5579eabfe0
8 changed files with 27 additions and 12 deletions
|
@ -38,7 +38,7 @@ void TimeProvider::setDiffToServer(double ms)
|
|||
{
|
||||
static int32_t lastTimeSync = 0;
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
chronos::systemtimeofday(&now);
|
||||
|
||||
/// clear diffBuffer if last update is older than a minute
|
||||
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
|
||||
|
|
|
@ -36,6 +36,20 @@ namespace chronos
|
|||
typedef std::chrono::microseconds usec;
|
||||
typedef std::chrono::nanoseconds nsec;
|
||||
|
||||
template <class Clock>
|
||||
inline static void timeofday(struct timeval *tv)
|
||||
{
|
||||
auto now = Clock::now();
|
||||
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
|
||||
tv->tv_sec = millisecs.count()/1000;
|
||||
tv->tv_usec = (millisecs.count()%1000)*1000;
|
||||
}
|
||||
|
||||
inline static void systemtimeofday(struct timeval *tv)
|
||||
{
|
||||
timeofday<std::chrono::system_clock>(tv);
|
||||
}
|
||||
|
||||
inline static void addUs(timeval& tv, int us)
|
||||
{
|
||||
if (us < 0)
|
||||
|
|
|
@ -252,7 +252,7 @@ static long uptime()
|
|||
uptime = trim_copy(uptime.substr(uptime.find(" sec = ") + 7));
|
||||
uptime.resize(uptime.find(","));
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
chronos::systemtimeofday(&now);
|
||||
try
|
||||
{
|
||||
return now.tv_sec - cpt::stoul(uptime);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <vector>
|
||||
#include <sys/time.h>
|
||||
#include "common/endian.h"
|
||||
#include "common/timeDefs.h"
|
||||
|
||||
|
||||
template<typename CharT, typename TraitsT = std::char_traits<CharT> >
|
||||
|
@ -65,7 +66,7 @@ struct tv
|
|||
tv()
|
||||
{
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
chronos::systemtimeofday(&t);
|
||||
sec = t.tv_sec;
|
||||
usec = t.tv_usec;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ void StreamServer::onDisconnect(StreamSession* streamSession)
|
|||
return;
|
||||
|
||||
clientInfo->connected = false;
|
||||
gettimeofday(&clientInfo->lastSeen, NULL);
|
||||
chronos::systemtimeofday(&clientInfo->lastSeen);
|
||||
Config::instance().save();
|
||||
if (controlServer_ != nullptr)
|
||||
{
|
||||
|
@ -445,7 +445,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
ClientInfoPtr client = Config::instance().getClientInfo(connection->clientId);
|
||||
if (client != nullptr)
|
||||
{
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
chronos::systemtimeofday(&client->lastSeen);
|
||||
client->connected = true;
|
||||
}
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
client->snapclient.protocolVersion = helloMsg.getProtocolVersion();
|
||||
client->config.instance = helloMsg.getInstance();
|
||||
client->connected = true;
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
chronos::systemtimeofday(&client->lastSeen);
|
||||
|
||||
// Assign and update stream
|
||||
PcmStreamPtr stream = streamManager_->getStream(group->streamId);
|
||||
|
|
|
@ -61,7 +61,7 @@ void FileStream::worker()
|
|||
|
||||
while (active_)
|
||||
{
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
long nextTick = chronos::getTickCount();
|
||||
try
|
||||
|
@ -97,7 +97,7 @@ void FileStream::worker()
|
|||
}
|
||||
else
|
||||
{
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
pcmListener_->onResync(this, currentTick - nextTick);
|
||||
nextTick = currentTick;
|
||||
|
|
|
@ -69,7 +69,7 @@ void PipeStream::worker()
|
|||
if (fd_ != -1)
|
||||
close(fd_);
|
||||
fd_ = open(uri_.path.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
long nextTick = chronos::getTickCount();
|
||||
try
|
||||
|
@ -117,7 +117,7 @@ void PipeStream::worker()
|
|||
}
|
||||
else
|
||||
{
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
pcmListener_->onResync(this, currentTick - nextTick);
|
||||
nextTick = currentTick;
|
||||
|
|
|
@ -154,7 +154,7 @@ void ProcessStream::worker()
|
|||
stderrReaderThread_ = thread(&ProcessStream::stderrReader, this);
|
||||
stderrReaderThread_.detach();
|
||||
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
long nextTick = chronos::getTickCount();
|
||||
try
|
||||
|
@ -199,7 +199,7 @@ void ProcessStream::worker()
|
|||
}
|
||||
else
|
||||
{
|
||||
gettimeofday(&tvChunk, NULL);
|
||||
chronos::systemtimeofday(&tvChunk);
|
||||
tvEncodedChunk_ = tvChunk;
|
||||
pcmListener_->onResync(this, currentTick - nextTick);
|
||||
nextTick = currentTick;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue