Skip to content

Commit

Permalink
fix examples: use statements, bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 9, 2023
1 parent 9f834e3 commit 564177c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
14 changes: 7 additions & 7 deletions lib/examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![allow(unused_variables, unused_must_use)]
#[macro_use]
extern crate sozu_lib as sozu;
extern crate sozu_lib;
#[macro_use]
extern crate sozu_command_lib as sozu_command;
extern crate sozu_command_lib;
extern crate time;

use std::{env, io::stdout, thread};

use anyhow::Context;

use sozu_command::{
use sozu_command_lib::{
channel::Channel,
config::ListenerBuilder,
logging::{Logger, LoggerBackend},
Expand Down Expand Up @@ -39,7 +39,7 @@ fn main() -> anyhow::Result<()> {

info!("MAIN\tstarting up");

sozu::metrics::setup(
sozu_lib::metrics::setup(
&"127.0.0.1:8125"
.parse()
.with_context(|| "Could not parse address for metrics setup")?,
Expand All @@ -56,7 +56,7 @@ fn main() -> anyhow::Result<()> {
let jg = thread::spawn(move || {
let max_buffers = 500;
let buffer_size = 16384;
sozu::http::start_http_worker(http_listener, channel, max_buffers, buffer_size);
sozu_lib::http::start_http_worker(http_listener, channel, max_buffers, buffer_size);
});

let http_front = RequestHttpFrontend {
Expand Down Expand Up @@ -93,14 +93,14 @@ fn main() -> anyhow::Result<()> {
info!("MAIN\tHTTP -> {:?}", command.read_message());
info!("MAIN\tHTTP -> {:?}", command.read_message());

let https_listener = ListenerBuilder::new_tcp("127.0.0.1:8443").to_tls()?;
let https_listener = ListenerBuilder::new_https("127.0.0.1:8443").to_tls()?;

let (mut command2, channel2) =
Channel::generate(1000, 10000).with_context(|| "should create a channel")?;
let jg2 = thread::spawn(move || {
let max_buffers = 500;
let buffer_size = 16384;
sozu::https::start_https_worker(https_listener, channel2, max_buffers, buffer_size)
sozu_lib::https::start_https_worker(https_listener, channel2, max_buffers, buffer_size)
});

let cert1 = include_str!("../assets/certificate.pem");
Expand Down
53 changes: 29 additions & 24 deletions lib/examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#![allow(unused_variables, unused_must_use)]
extern crate sozu_lib as sozu;
#[macro_use]
extern crate sozu_command_lib as sozu_command;
extern crate time;

#[macro_use]
extern crate sozu_command_lib;

use std::{collections::BTreeMap, env, io::stdout, thread};

use anyhow::Context;
use sozu_command::proto::command::request::RequestType;

use crate::sozu_command::{
use sozu_command_lib::{
channel::Channel,
config::ListenerBuilder,
info,
logging::{Logger, LoggerBackend},
proto::command::{
AddBackend, LoadBalancingParams, PathRule, Request, RequestHttpFrontend, RulePosition,
request::RequestType, AddBackend, LoadBalancingParams, PathRule, Request,
RequestHttpFrontend, RulePosition,
},
request::WorkerRequest,
};
Expand All @@ -40,13 +41,14 @@ fn main() -> anyhow::Result<()> {

let http_listener = ListenerBuilder::new_http("127.0.0.1:8080").to_http()?;

let (mut command, channel) =
let (mut command_channel, proxy_channel) =
Channel::generate(1000, 10000).with_context(|| "should create a channel")?;

let jg = thread::spawn(move || {
let max_buffers = 500;
let buffer_size = 16384;
sozu::http::start_http_worker(http_listener, channel, max_buffers, buffer_size);
sozu_lib::http::start_http_worker(http_listener, proxy_channel, max_buffers, buffer_size)
.expect("The worker could not be started, or shut down");
});

let http_front = RequestHttpFrontend {
Expand All @@ -66,26 +68,29 @@ fn main() -> anyhow::Result<()> {
backend_id: String::from("test-0"),
address: "127.0.0.1:8000".to_string(),
load_balancing_parameters: Some(LoadBalancingParams::default()),
sticky_id: None,
backup: None,
..Default::default()
};

command.write_message(&WorkerRequest {
id: String::from("ID_ABCD"),
content: Request {
request_type: Some(RequestType::AddHttpFrontend(http_front)),
},
});
command_channel
.write_message(&WorkerRequest {
id: String::from("ID_ABCD"),
content: Request {
request_type: Some(RequestType::AddHttpFrontend(http_front)),
},
})
.expect("Could not send AddHttpFrontend request");

command.write_message(&WorkerRequest {
id: String::from("ID_EFGH"),
content: Request {
request_type: Some(RequestType::AddBackend(http_backend)),
},
});
command_channel
.write_message(&WorkerRequest {
id: String::from("ID_EFGH"),
content: Request {
request_type: Some(RequestType::AddBackend(http_backend)),
},
})
.expect("Could not send AddBackend request");

println!("HTTP -> {:?}", command.read_message());
println!("HTTP -> {:?}", command.read_message());
println!("HTTP -> {:?}", command_channel.read_message());
println!("HTTP -> {:?}", command_channel.read_message());

let _ = jg.join();
info!("good bye");
Expand Down
8 changes: 4 additions & 4 deletions lib/examples/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![allow(unused_variables, unused_must_use)]
extern crate sozu_lib as sozu;
extern crate sozu_lib;
#[macro_use]
extern crate sozu_command_lib as sozu_command;
extern crate sozu_command_lib;
extern crate time;

use std::{io::stdout, thread};

use anyhow::Context;
use sozu_command::{
use sozu_command_lib::{
channel::Channel,
logging::{Logger, LoggerBackend},
proto::command::{
Expand Down Expand Up @@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
LoggerBackend::Stdout(stdout()),
None,
);
sozu::tcp::start_tcp_worker(listener, max_buffers, buffer_size, channel);
sozu_lib::tcp::start_tcp_worker(listener, max_buffers, buffer_size, channel);
});

let tcp_front = RequestTcpFrontend {
Expand Down
1 change: 1 addition & 0 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ impl Server {
Ok(server)
}

/// The server runs in a loop until a shutdown is ordered
pub fn run(&mut self) {
let mut events = Events::with_capacity(1024); // TODO: make event capacity configurable?
self.last_sessions_len = self.sessions.borrow().slab.len();
Expand Down

0 comments on commit 564177c

Please sign in to comment.