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
|
// ask the task class to handle the task
|
||||||
task->handle(this->context);
|
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
|
// free the address
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "ClientTask.hpp"
|
#include "ClientTask.hpp"
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
namespace drp::task {
|
namespace drp::task {
|
||||||
|
|
||||||
|
@ -9,6 +11,8 @@ void ClientTask::handle(Context& context) {
|
||||||
|
|
||||||
// TODO(Faraphel): check if the server is still reachable.
|
// TODO(Faraphel): check if the server is still reachable.
|
||||||
// if connection lost, go back to undefined mode.
|
// 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 "ServerTask.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <mpg123.h>
|
#include <mpg123.h>
|
||||||
|
@ -8,7 +9,6 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../../packets/audio/AudioPacketData.hpp"
|
#include "../../packets/audio/AudioPacketData.hpp"
|
||||||
#include "../../utils/audio.hpp"
|
#include "../../utils/audio.hpp"
|
||||||
|
@ -66,6 +66,7 @@ void ServerTask::handle(Context& context) {
|
||||||
&done
|
&done
|
||||||
) != MPG123_OK) {
|
) != MPG123_OK) {
|
||||||
std::cerr << "[Server] Could not read audio data from file." << std::endl;
|
std::cerr << "[Server] Could not read audio data from file." << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ void ServerTask::handle(Context& context) {
|
||||||
context.broadcastAddressInfo->ai_addrlen
|
context.broadcastAddressInfo->ai_addrlen
|
||||||
) == -1) {
|
) == -1) {
|
||||||
std::cerr << "[Server] Could not send audio packet: " << strerror(errno) << std::endl;
|
std::cerr << "[Server] Could not send audio packet: " << strerror(errno) << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bits/random.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include "../../Context.hpp"
|
#include "../../Context.hpp"
|
||||||
|
@ -54,7 +53,12 @@ void UndefinedTask::handle(Context& context) {
|
||||||
return;
|
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
|
// prepare a search message
|
||||||
|
|
Loading…
Reference in a new issue