Message sending

This commit is contained in:
juju committed 2020-05-05 20:50:55 +02:00
1 parent 6b80cc68ce
commit 0354ce0bea
5 files changed
+61

No files matched your search

+27
View File
@@ -21,7 +21,33 @@ namespace paxos
void SendEW::operator()()
{
shared_socket sock = connection_->get_socket();
auto buffer = connection_->get_buffer_out();
std::string response = buffer.to_string();
log("Sending a message: ", blue);
log(response, white);
ssize_t write = 0;
try
{
write = sock->send(response.c_str(), response.size());
}
catch (const std::system_error& e)
{
std::cerr << "Connection closed while sending\n";
event_register.unregister_ew(this);
return;
}
if (write == -1)
return;
buffer.pop_front(write);
if (!buffer.empty())
return;
event_register.unregister_ew(this);
}
static shared_socket connect_to_ip_port(std::string ip, std::string port)
@@ -63,6 +89,7 @@ namespace paxos
catch (const ConnectionFailed& e)
{
log("Could not connect to " + legislator->config_.name, red);
return;
}
shared_connection connection = std::make_shared<Connection>(socket);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.