Skip to content
Snippets Groups Projects
Commit edae0f63 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add locks to peer destructor

parent 6d9fa2ac
No related branches found
No related tags found
1 merge request!10Bug/visionfreeze
Pipeline #10896 passed
...@@ -196,22 +196,6 @@ class Peer { ...@@ -196,22 +196,6 @@ class Peer {
} }
} }
/*template <typename... ARGS>
int _send(const std::string &t, ARGS... args);
template <typename... ARGS>
int _send(const array &b, ARGS... args);
template <typename T, typename... ARGS>
int _send(const std::vector<T> &t, ARGS... args);
template <typename... Types, typename... ARGS>
int _send(const std::tuple<Types...> &t, ARGS... args);
template <typename T, typename... ARGS,
ENABLE_IF(std::is_trivial<T>::value && !std::is_pointer<T>::value)>
int _send(const T &t, ARGS... args);*/
private: // Data private: // Data
Status status_; Status status_;
int sock_; int sock_;
......
...@@ -310,7 +310,7 @@ void Peer::data() { ...@@ -310,7 +310,7 @@ void Peer::data() {
} }
bool Peer::_data() { bool Peer::_data() {
// std::unique_lock<std::mutex> lk(recv_mtx_); std::unique_lock<std::mutex> lk(recv_mtx_);
recv_buf_.reserve_buffer(kMaxMessage); recv_buf_.reserve_buffer(kMaxMessage);
int rc = ftl::net::internal::recv(sock_, recv_buf_.buffer(), kMaxMessage, 0); int rc = ftl::net::internal::recv(sock_, recv_buf_.buffer(), kMaxMessage, 0);
...@@ -556,6 +556,8 @@ int Peer::_send() { ...@@ -556,6 +556,8 @@ int Peer::_send() {
} }
Peer::~Peer() { Peer::~Peer() {
std::unique_lock<std::mutex> lk1(send_mtx_);
std::unique_lock<std::mutex> lk2(recv_mtx_);
close(); close();
delete disp_; delete disp_;
......
...@@ -250,7 +250,10 @@ void Universe::_run() { ...@@ -250,7 +250,10 @@ void Universe::_run() {
//Some kind of error occured, it is usually possible to recover from this. //Some kind of error occured, it is usually possible to recover from this.
if (selres < 0) { if (selres < 0) {
std::cout << "SELECT ERROR " << selres << " - " << strerror(errno) << std::endl; switch (errno) {
case 9 : continue; // Bad file descriptor = socket closed
default : std::cout << "Unknown select error: " << strerror(errno) << std::endl;
}
continue; continue;
} else if (selres == 0) { } else if (selres == 0) {
// Timeout, nothing to do... // Timeout, nothing to do...
...@@ -266,12 +269,6 @@ void Universe::_run() { ...@@ -266,12 +269,6 @@ void Universe::_run() {
int rsize = sizeof(sockaddr_storage); int rsize = sizeof(sockaddr_storage);
sockaddr_storage addr; sockaddr_storage addr;
//int freeclient = freeSocket();
//if (freeclient >= 0) {
// TODO Limit connection rate or allow a pause in accepting
// TODO Send auto reject message under heavy load
//Finally accept this client connection. //Finally accept this client connection.
int csock = accept(l->_socket(), (sockaddr*)&addr, (socklen_t*)&rsize); int csock = accept(l->_socket(), (sockaddr*)&addr, (socklen_t*)&rsize);
...@@ -283,7 +280,6 @@ void Universe::_run() { ...@@ -283,7 +280,6 @@ void Universe::_run() {
peer_ids_[p.id()] = &p; peer_ids_[p.id()] = &p;
}); });
} }
//}
} }
} }
} }
...@@ -293,12 +289,7 @@ void Universe::_run() { ...@@ -293,12 +289,7 @@ void Universe::_run() {
if (s != NULL && s->isValid()) { if (s != NULL && s->isValid()) {
//If message received from this client then deal with it //If message received from this client then deal with it
if (FD_ISSET(s->_socket(), &sfdread_)) { if (FD_ISSET(s->_socket(), &sfdread_)) {
//s->data();
//std::cout << "QUEUE DATA PROC" << std::endl;
//p.push([](int id, Peer *s) {
// std::cout << "Processing in thread " << std::to_string(id) << std::endl;
s->data(); s->data();
//}, s);
} }
if (FD_ISSET(s->_socket(), &sfderror_)) { if (FD_ISSET(s->_socket(), &sfderror_)) {
s->socketError(); s->socketError();
......
...@@ -238,7 +238,7 @@ TEST_CASE("Universe::publish()", "") { ...@@ -238,7 +238,7 @@ TEST_CASE("Universe::publish()", "") {
sleep_for(milliseconds(50)); sleep_for(milliseconds(50));
p->close(); p->close();
sleep_for(milliseconds(500)); sleep_for(milliseconds(100));
a.publish("ftl://test2", 56); a.publish("ftl://test2", 56);
sleep_for(milliseconds(50)); sleep_for(milliseconds(50));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment