Message sending
This commit is contained in:
parent
6b80cc68ce
commit
0354ce0bea
16
config-files/two-legislators/two-legislators1.json
Normal file
16
config-files/two-legislators/two-legislators1.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"legislators" : [
|
||||||
|
{
|
||||||
|
"ip" : "127.0.0.1",
|
||||||
|
"port" : 8000,
|
||||||
|
"name" : "legislator1",
|
||||||
|
"self" : true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ip" : "127.0.0.1",
|
||||||
|
"port" : 8001,
|
||||||
|
"name" : "legislator2",
|
||||||
|
"self" : false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
16
config-files/two-legislators/two-legislators2.json
Normal file
16
config-files/two-legislators/two-legislators2.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"legislators" : [
|
||||||
|
{
|
||||||
|
"ip" : "127.0.0.1",
|
||||||
|
"port" : 8000,
|
||||||
|
"name" : "legislator1",
|
||||||
|
"self" : false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ip" : "127.0.0.1",
|
||||||
|
"port" : 8001,
|
||||||
|
"name" : "legislator2",
|
||||||
|
"self" : true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
1
legislator1/last-tried.txt
Normal file
1
legislator1/last-tried.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
9
|
1
legislator2/last-tried.txt
Normal file
1
legislator2/last-tried.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
0
|
@ -21,7 +21,33 @@ namespace paxos
|
|||||||
|
|
||||||
void SendEW::operator()()
|
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)
|
static shared_socket connect_to_ip_port(std::string ip, std::string port)
|
||||||
@ -63,6 +89,7 @@ namespace paxos
|
|||||||
catch (const ConnectionFailed& e)
|
catch (const ConnectionFailed& e)
|
||||||
{
|
{
|
||||||
log("Could not connect to " + legislator->config_.name, red);
|
log("Could not connect to " + legislator->config_.name, red);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_connection connection = std::make_shared<Connection>(socket);
|
shared_connection connection = std::make_shared<Connection>(socket);
|
||||||
|
Loading…
Reference in New Issue
Block a user