zm::Select: Convert API to std::chrono
This commit is contained in:
parent
c823b9c00e
commit
3e8b10d813
|
@ -615,19 +615,7 @@ bool zm::TcpUnixServer::accept(TcpUnixSocket *&newSocket) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zm::Select::setTimeout(int timeout) {
|
void zm::Select::setTimeout(Microseconds timeout) {
|
||||||
mTimeout.tv_sec = timeout;
|
|
||||||
mTimeout.tv_usec = 0;
|
|
||||||
mHasTimeout = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zm::Select::setTimeout(double timeout) {
|
|
||||||
mTimeout.tv_sec = int(timeout);
|
|
||||||
mTimeout.tv_usec = suseconds_t((timeout - mTimeout.tv_sec) * 1000000.0);
|
|
||||||
mHasTimeout = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zm::Select::setTimeout(timeval timeout) {
|
|
||||||
mTimeout = timeout;
|
mTimeout = timeout;
|
||||||
mHasTimeout = true;
|
mHasTimeout = true;
|
||||||
}
|
}
|
||||||
|
@ -703,7 +691,7 @@ void zm::Select::clearWriters() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int zm::Select::wait() {
|
int zm::Select::wait() {
|
||||||
timeval tempTimeout = mTimeout;
|
timeval tempTimeout = zm::chrono::duration_cast<timeval>(mTimeout);
|
||||||
timeval *selectTimeout = mHasTimeout ? &tempTimeout : nullptr;
|
timeval *selectTimeout = mHasTimeout ? &tempTimeout : nullptr;
|
||||||
|
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "zm_exception.h"
|
#include "zm_exception.h"
|
||||||
#include "zm_logger.h"
|
#include "zm_logger.h"
|
||||||
|
#include "zm_time.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
@ -560,13 +561,9 @@ class Select {
|
||||||
typedef std::vector<CommsBase *> CommsList;
|
typedef std::vector<CommsBase *> CommsList;
|
||||||
|
|
||||||
Select() : mHasTimeout(false), mMaxFd(-1) {}
|
Select() : mHasTimeout(false), mMaxFd(-1) {}
|
||||||
explicit Select(timeval timeout) : mMaxFd(-1) { setTimeout(timeout); }
|
explicit Select(Microseconds timeout) : mMaxFd(-1) { setTimeout(timeout); }
|
||||||
explicit Select(int timeout) : mMaxFd(-1) { setTimeout(timeout); }
|
|
||||||
explicit Select(double timeout) : mMaxFd(-1) { setTimeout(timeout); }
|
|
||||||
|
|
||||||
void setTimeout(int timeout);
|
void setTimeout(Microseconds timeout);
|
||||||
void setTimeout(double timeout);
|
|
||||||
void setTimeout(timeval timeout);
|
|
||||||
void clearTimeout();
|
void clearTimeout();
|
||||||
|
|
||||||
void calcMaxFd();
|
void calcMaxFd();
|
||||||
|
@ -590,7 +587,7 @@ class Select {
|
||||||
CommsList mReadable;
|
CommsList mReadable;
|
||||||
CommsList mWriteable;
|
CommsList mWriteable;
|
||||||
bool mHasTimeout;
|
bool mHasTimeout;
|
||||||
timeval mTimeout;
|
Microseconds mTimeout;
|
||||||
int mMaxFd;
|
int mMaxFd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -269,7 +269,7 @@ void RtpCtrlThread::Run() {
|
||||||
|
|
||||||
// The only reason I can think of why we would have a timeout period is so that we can regularly send RR packets.
|
// The only reason I can think of why we would have a timeout period is so that we can regularly send RR packets.
|
||||||
// Why 10 seconds? If anything I think this should be whatever timeout value was given in the DESCRIBE response
|
// Why 10 seconds? If anything I think this should be whatever timeout value was given in the DESCRIBE response
|
||||||
zm::Select select(10 );
|
zm::Select select(Seconds(10));
|
||||||
select.addReader( &rtpCtrlServer );
|
select.addReader( &rtpCtrlServer );
|
||||||
|
|
||||||
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
||||||
|
|
|
@ -76,7 +76,7 @@ void RtpDataThread::Run() {
|
||||||
}
|
}
|
||||||
Debug(3, "Bound to %s:%d", mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort());
|
Debug(3, "Bound to %s:%d", mRtpSource.getLocalHost().c_str(), mRtpSource.getLocalDataPort());
|
||||||
|
|
||||||
zm::Select select(3);
|
zm::Select select(Seconds(3));
|
||||||
select.addReader(&rtpDataSocket);
|
select.addReader(&rtpDataSocket);
|
||||||
|
|
||||||
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
unsigned char buffer[ZM_NETWORK_BUFSIZ];
|
||||||
|
|
|
@ -621,7 +621,7 @@ void RtspThread::Run() {
|
||||||
RtpDataThread rtpDataThread( *this, *source );
|
RtpDataThread rtpDataThread( *this, *source );
|
||||||
RtpCtrlThread rtpCtrlThread( *this, *source );
|
RtpCtrlThread rtpCtrlThread( *this, *source );
|
||||||
|
|
||||||
zm::Select select(double(config.http_timeout)/1000.0 );
|
zm::Select select(Milliseconds(config.http_timeout));
|
||||||
select.addReader( &mRtspSocket );
|
select.addReader( &mRtspSocket );
|
||||||
|
|
||||||
Buffer buffer( ZM_NETWORK_BUFSIZ );
|
Buffer buffer( ZM_NETWORK_BUFSIZ );
|
||||||
|
|
Loading…
Reference in New Issue