Skip to content

Commit

Permalink
Set socket options on broker's connections as well.
Browse files Browse the repository at this point in the history
This completes #4.
  • Loading branch information
nfachan committed Oct 21, 2024
1 parent 090f679 commit 936e418
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions crates/maelstrom-broker/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use maelstrom_base::{
};
use maelstrom_util::{
cache::{fs::std::Fs, TempFileFactory},
net,
net::{self, AsRawFdExt},
};
use serde::Serialize;
use slog::{debug, error, info, o, warn, Logger};
Expand Down Expand Up @@ -103,12 +103,19 @@ pub async fn connection_main<IdT, FromSchedulerMessageT, ReaderFutureT, WriterFu
}

async fn unassigned_connection_main(
mut socket: TcpStream,
socket: TcpStream,
scheduler_sender: SchedulerSender,
id_vendor: Arc<IdVendor>,
temp_file_factory: TempFileFactory<Fs>,
log: Logger,
) {
let mut socket = match socket.set_socket_options() {
Ok(socket) => socket,
Err(err) => {
warn!(log, "error setting socket options"; "error" => %err);
return;
}
};
match net::read_message_from_async_socket(&mut socket, &log).await {
Ok(Hello::Client) => {
let (read_stream, write_stream) = socket.into_split();
Expand Down
6 changes: 4 additions & 2 deletions crates/maelstrom-client-process/src/artifact_pusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use maelstrom_base::{
proto::{ArtifactPusherToBroker, BrokerToArtifactPusher, Hello},
Sha256Digest,
};
use maelstrom_util::{async_fs::Fs, config::common::BrokerAddr, net};
use maelstrom_util::{async_fs::Fs, config::common::BrokerAddr, net, net::AsRawFdExt as _};
use slog::Logger;
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down Expand Up @@ -32,7 +32,9 @@ async fn push_one_artifact(
digest: Sha256Digest,
log: &Logger,
) -> Result<()> {
let mut stream = TcpStream::connect(broker_addr.inner()).await?;
let mut stream = TcpStream::connect(broker_addr.inner())
.await?
.set_socket_options()?;
net::write_message_to_async_socket(&mut stream, Hello::ArtifactPusher, log).await?;

let fs = Fs::new();
Expand Down
3 changes: 2 additions & 1 deletion crates/maelstrom-client-process/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use maelstrom_container::{
use maelstrom_util::{
async_fs,
config::common::{BrokerAddr, CacheSize, InlineLimit, Slots},
net,
net::{self, AsRawFdExt as _},
root::RootBuf,
signal,
};
Expand Down Expand Up @@ -320,6 +320,7 @@ impl Client {
TcpStream::connect(broker_addr.inner())
.await
.with_context(|| format!("failed to connect to {broker_addr}"))?
.set_socket_options()?
.into_split();
debug!(log, "client connected to broker"; "broker_addr" => ?broker_addr);

Expand Down

0 comments on commit 936e418

Please sign in to comment.