mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 16:30:39 +02:00
made JitterTester work on windows
This commit is contained in:
parent
395f643f1b
commit
029ef962b7
1 changed files with 118 additions and 90 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <cerrno>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <MovingMinMaxAvg.h> // for MovingMinMaxAvg
|
||||
|
@ -58,14 +59,17 @@ int main(int argc, const char * argv[]) {
|
|||
void runSend(const char* addressOption, int port, int gap, int size, int report) {
|
||||
std::cout << "runSend...\n";
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
printf("WSAStartup failed with error %d\n", WSAGetLastError());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int sockfd;
|
||||
struct sockaddr_in servaddr;
|
||||
|
||||
char* outputBuffer = new char[size];
|
||||
memset(outputBuffer, 0, size);
|
||||
|
||||
quint16 outgoingSequenceNumber = 0;
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
|
@ -73,16 +77,20 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
|||
servaddr.sin_addr.s_addr = inet_addr(addressOption);
|
||||
servaddr.sin_port = htons(port);
|
||||
|
||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
||||
|
||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
||||
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
||||
|
||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats
|
||||
|
||||
const int SAMPLES_PER_REPORT = report * MSEC_TO_USEC / gap;
|
||||
|
||||
std::cout << "SAMPLES_PER_REPORT:" << SAMPLES_PER_REPORT << "\n";
|
||||
|
||||
|
||||
char* outputBuffer = new char[size];
|
||||
memset(outputBuffer, 0, size);
|
||||
|
||||
quint16 outgoingSequenceNumber = 0;
|
||||
|
||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS);
|
||||
MovingMinMaxAvg<int> timeGapsPerReport(1, SAMPLES_PER_REPORT);
|
||||
|
||||
StDev stDevReportInterval;
|
||||
|
@ -103,7 +111,10 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
|||
// pack seq num
|
||||
memcpy(outputBuffer, &outgoingSequenceNumber, sizeof(quint16));
|
||||
|
||||
sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
||||
int n = sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
||||
if (n < 0) {
|
||||
std::cout << "Send error: " << strerror(errno) << "\n";
|
||||
}
|
||||
outgoingSequenceNumber++;
|
||||
|
||||
int gapDifferece = actualGap - gap;
|
||||
|
@ -144,18 +155,27 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
|||
}
|
||||
}
|
||||
}
|
||||
delete[] outputBuffer;
|
||||
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void runReceive(const char* addressOption, int port, int gap, int size, int report) {
|
||||
std::cout << "runReceive...\n";
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
printf("WSAStartup failed with error %d\n", WSAGetLastError());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int sockfd, n;
|
||||
struct sockaddr_in myaddr;
|
||||
|
||||
char* inputBuffer = new char[size];
|
||||
memset(inputBuffer, 0, size);
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
memset(&myaddr, 0, sizeof(myaddr));
|
||||
|
@ -163,22 +183,23 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
|||
myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
myaddr.sin_port = htons(port);
|
||||
|
||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
||||
|
||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
||||
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
||||
|
||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats
|
||||
|
||||
const int SAMPLES_PER_REPORT = report * MSEC_TO_USEC / gap;
|
||||
|
||||
std::cout << "SAMPLES_PER_REPORT:" << SAMPLES_PER_REPORT << "\n";
|
||||
|
||||
MovingMinMaxAvg<int> timeGapsPerReport(1, SAMPLES_PER_REPORT);
|
||||
|
||||
const int REPORTS_FOR_30_SECONDS = 30 * MSECS_PER_SECOND / report;
|
||||
|
||||
std::cout << "REPORTS_FOR_30_SECONDS:" << REPORTS_FOR_30_SECONDS << "\n";
|
||||
|
||||
|
||||
char* inputBuffer = new char[size];
|
||||
memset(inputBuffer, 0, size);
|
||||
|
||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS);
|
||||
MovingMinMaxAvg<int> timeGapsPerReport(1, SAMPLES_PER_REPORT);
|
||||
|
||||
SequenceNumberStats seqStats(REPORTS_FOR_30_SECONDS);
|
||||
|
||||
StDev stDevReportInterval;
|
||||
|
@ -195,6 +216,9 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
|||
|
||||
while (true) {
|
||||
n = recvfrom(sockfd, inputBuffer, size, 0, NULL, NULL); // we don't care about where it came from
|
||||
if (n < 0) {
|
||||
std::cout << "Receive error: " << strerror(errno) << "\n";
|
||||
}
|
||||
|
||||
// parse seq num
|
||||
quint16 incomingSequenceNumber = *(reinterpret_cast<quint16*>(inputBuffer));
|
||||
|
@ -260,5 +284,9 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] inputBuffer;
|
||||
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue