Skip to content

Instantly share code, notes, and snippets.

View yoshuawuyts's full-sized avatar

Yosh yoshuawuyts

View GitHub Profile
// required
let listener = TcpListener::bind((args.address.as_str(), args.port))?;
// what we want to be able to do
let listener = TcpListener::bind((&args.address, args.port))?;
#!/bin/bash
set +ex
fr() {
rg -l "$1" | xargs sed -i "s/$1/$2/g"
}
# setup
fr 'atomic_waker' 'atomic_cx'
#!/usr/local/bin/node
let dgram = require('dgram')
let socket = dgram.createSocket('udp4', (msg, rinfo) => {
let peer = `${rinfo.address}:${rinfo.port}`
socket.send(msg, peer, (err) => {
if (err) peer.close()
console.log(`Sent ${rinfo.size} of ${rinfo.size} bytes to ${peer}`)
})

Current

error: only the main function can be tagged with #[foob]
  --> tests/hello.rs:45:1
   |
45 | fn hello() {
   | ^^
error: aborting due to previous error
error: Could not compile `runtime`.
To learn more, run the command again with --verbose. [runtime:1]
let config = Config::from_args();
let mut app = tide::App::new(())
.address(config.address)
.port(config.port);
app.at("/").get(reply);
app.serve();
fn main() -> io::Result<()> {
executor::block_on(async {
let listener = TcpListener::bind(&"127.0.0.1:7878".parse().unwrap())?;
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
let stream = stream?;
let addr = stream.peer_addr()?;
juliex::spawn(async move {
let (mut reader, mut writer) = stream.split();
#[derive(StructOpt, PartialEq, Debug)]
pub struct Cli {
bbox_1: u32,
bbox_2: u32,
bbox_3: u32,
bbox_4: u32,
}
fn main () {
let args = Cli::from_args();

Layering RPC over duplex connections

This is just a thing I've been thinking about for a while, and I'm not sure what the best structure is here. I'd be keen to hear more about examples, literature, and experiences on how people have approached this. I feel it's an important thing to start thinking about early when talking about networking, especially with HTTP/2 & HTTP/3 on the horizon.

Background

Traditional HTTP servers can be expressed as asynchronous transform functions:

use wasm_bindgen::prelude::Closure;
use wasm_bindgen::JsCast;
use web_sys::{Document, EventTarget};
let document = Document::new().map_err(|_| ErrorKind::Document)?;
let target: EventTarget = document.into();
let cb = Closure::wrap(Box::new(move || {
println!("hello world from WASM");
}) as Box<Fn()>);
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}