moved sleep into the tasks instead of the event loop
This commit is contained in:
parent
4f84c8186a
commit
1c5442c267
4 changed files with 13 additions and 7 deletions
|
@ -109,10 +109,6 @@ void EventManager::loopSender() {
|
|||
|
||||
// ask the task class to handle the task
|
||||
task->handle(this->context);
|
||||
|
||||
// wait a second
|
||||
// TODO(Faraphel): might be moved to the tasks directly ? what if they want a lower cooldown ?
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
// free the address
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "ClientTask.hpp"
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace drp::task {
|
||||
|
||||
|
@ -9,6 +11,8 @@ void ClientTask::handle(Context& context) {
|
|||
|
||||
// TODO(Faraphel): check if the server is still reachable.
|
||||
// if connection lost, go back to undefined mode.
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ServerTask.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mpg123.h>
|
||||
|
@ -8,7 +9,6 @@
|
|||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <sys/socket.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../../packets/audio/AudioPacketData.hpp"
|
||||
#include "../../utils/audio.hpp"
|
||||
|
@ -66,6 +66,7 @@ void ServerTask::handle(Context& context) {
|
|||
&done
|
||||
) != MPG123_OK) {
|
||||
std::cerr << "[Server] Could not read audio data from file." << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -93,6 +94,7 @@ void ServerTask::handle(Context& context) {
|
|||
context.broadcastAddressInfo->ai_addrlen
|
||||
) == -1) {
|
||||
std::cerr << "[Server] Could not send audio packet: " << strerror(errno) << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <bits/random.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "../../Context.hpp"
|
||||
|
@ -54,7 +53,12 @@ void UndefinedTask::handle(Context& context) {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO(Faraphel): elect a server among those capable of emitting.
|
||||
// TODO(Faraphel): check if we have the lowest average ping out of all the peers. If yes, become the server.
|
||||
// Others peers will connect to us on their next loop.
|
||||
if (!context.me.serverEnabled)
|
||||
return;
|
||||
|
||||
...
|
||||
}
|
||||
|
||||
// prepare a search message
|
||||
|
|
Loading…
Reference in a new issue