diff --git a/config-files/two-legislators/two-legislators1.json b/config-files/two-legislators/two-legislators1.json new file mode 100644 index 0000000..32d9513 --- /dev/null +++ b/config-files/two-legislators/two-legislators1.json @@ -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 + } + ] +} diff --git a/config-files/two-legislators/two-legislators2.json b/config-files/two-legislators/two-legislators2.json new file mode 100644 index 0000000..4197286 --- /dev/null +++ b/config-files/two-legislators/two-legislators2.json @@ -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 + } + ] +} diff --git a/legislator1/last-tried.txt b/legislator1/last-tried.txt new file mode 100644 index 0000000..f11c82a --- /dev/null +++ b/legislator1/last-tried.txt @@ -0,0 +1 @@ +9 \ No newline at end of file diff --git a/legislator2/last-tried.txt b/legislator2/last-tried.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/legislator2/last-tried.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/src/events/send.cc b/src/events/send.cc index 36d0c17..7c22557 100644 --- a/src/events/send.cc +++ b/src/events/send.cc @@ -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(socket);