Browse Source

starting to work on spawning and communicating with a process

master
Weird Constructor 4 years ago
parent
commit
c3c69a616f
  1. 123
      Cargo.lock
  2. 2
      Cargo.toml
  3. 98
      src/main.rs
  4. 2
      webdata/index.html
  5. 2
      webdata/main.js

123
Cargo.lock generated

@ -1,6 +1,11 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "arc-swap"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "arrayvec"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -278,6 +283,27 @@ dependencies = [
]
[[package]]
name = "mio-named-pipes"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mio-uds"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "miow"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -289,6 +315,15 @@ dependencies = [
]
[[package]]
name = "miow"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"socket2 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "net2"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -458,6 +493,11 @@ dependencies = [
]
[[package]]
name = "ryu"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "scopeguard"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -481,6 +521,34 @@ version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_json"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "signal-hook"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"signal-hook-registry 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "signal-hook-registry"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -491,6 +559,17 @@ version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "socket2"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -570,6 +649,21 @@ dependencies = [
]
[[package]]
name = "tokio-process"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-reactor"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -588,6 +682,22 @@ dependencies = [
]
[[package]]
name = "tokio-signal"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tokio-sync"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -666,6 +776,8 @@ dependencies = [
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-process 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -707,6 +819,7 @@ dependencies = [
]
[metadata]
"checksum arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "bc4662175ead9cd84451d5c35070517777949a2ed84551764129cedb88384841"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
@ -740,7 +853,10 @@ dependencies = [
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3"
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
@ -760,12 +876,17 @@ dependencies = [
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be"
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "72ab58f1fda436857e6337dcb6a5aaa34f16c5ddc87b3a8b6ef7a212f90b9c5a"
"checksum signal-hook-registry 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cded4ffa32146722ec54ab1f16320568465aa922aa9ab4708129599740da85d7"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum socket2 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4e626972d3593207547f14bf5fc9efa4d0e7283deb73fef1dff313dae9ab8878"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum string 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0bbfb8937e38e34c3444ff00afb28b0811d9554f15c5ad64d12b0308d1d1995"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
@ -774,7 +895,9 @@ dependencies = [
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443"
"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e"
"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926"
"checksum tokio-process 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88e1281e412013f1ff5787def044a9577a0bed059f451e835f1643201f8b777d"
"checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce"
"checksum tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dd6dc5276ea05ce379a16de90083ec80836440d5ef8a6a39545a3207373b8296"
"checksum tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2162248ff317e2bc713b261f242b69dbb838b85248ed20bb21df56d60ea4cae7"
"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119"
"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2"

2
Cargo.toml

@ -9,3 +9,5 @@ build="build.rs"
hyper="0.12.29"
serde="1.0.92"
futures="0.1"
tokio-process="0.2.3"
serde_json="1.0.39"

98
src/main.rs

@ -1,8 +1,14 @@
extern crate hyper;
extern crate futures;
extern crate tokio_process;
extern crate serde;
extern crate serde_json;
//use serde_json::{Result, Value};
use serde_json::{Value};
use hyper::{Body, Request, Response, Server, Method, StatusCode};
use hyper::rt::Future;
//use hyper::rt::{self, Future, Stream};
use hyper::rt::{Future, Stream};
use hyper::service::service_fn;
use hyper::header::{HeaderName, HeaderValue};
use futures::future;
@ -10,6 +16,7 @@ use std::path::{Path, PathBuf};
type BoxFut = Box<dyn Future<Item=Response<Body>, Error=hyper::Error> + Send>;
#[allow(dead_code)]
fn mime_for_ext(s: &str) -> String {
String::from(
match s {
@ -22,18 +29,47 @@ fn mime_for_ext(s: &str) -> String {
)
}
#[allow(dead_code)]
fn hello_world(req: Request<Body>) -> BoxFut {
let mut response = Response::new(Body::empty());
match (req.method(), req.uri().path()) {
let method : hyper::Method = req.method().clone();
let path = String::from(req.uri().path());
let p : &str = &path;
match (&method, p) {
(&Method::GET, "/") => {
*response.body_mut() = Body::from("Try POSTing data to /echo");
},
(&Method::POST, "/echo") => {
*response.body_mut() = Body::from("WURST");
},
(&Method::POST, path) => {
let myp = String::from(path);
let res = req.into_body().concat2().map(move |chunk| {
let body : Vec<u8> = chunk.iter().cloned().collect();
match String::from_utf8(body) {
Ok(b) => {
match serde_json::from_str::<Value>(&b) {
Ok(v) => {
println!("FO {} => {}", myp, v);
},
Err(_) => {
*response.status_mut() = StatusCode::BAD_REQUEST;
},
}
},
_ => {
*response.status_mut() = StatusCode::BAD_REQUEST;
},
};
response
});
return Box::new(res);
},
(&Method::GET, path) => {
println!("GET REQUEST: {}", path);
let path = Path::new(path);
if path.starts_with("/files/") {
let webdata_path = match path.strip_prefix("/files") {
@ -76,7 +112,59 @@ fn hello_world(req: Request<Body>) -> BoxFut {
Box::new(future::ok(response))
}
fn main() {
#[allow(dead_code)]
fn start_leela() {
// /home/weictr/devel/leela/leela-zero
// => /home/weictr/devel/leela/lizzie/Lizzie/network.gz
}
//fn feed_cat(mut cat: Child, n: usize) -> Box<Future<Item = ExitStatus, Error = io::Error>> {
// let stdin = cat.stdin().take().unwrap();
// let stdout = cat.stdout().take().unwrap();
//
// debug!("starting to feed");
// // Produce n lines on the child's stdout.
// let numbers = stream::iter_ok(0..n);
// let write = numbers.fold(stdin, |stdin, i| {
// debug!("sending line {} to child", i);
// write_all(stdin, format!("line {}\n", i).into_bytes()).map(|p| p.0)
// }).map(|_| ());
//
// // Try to read `n + 1` lines, ensuring the last one is empty
// // (i.e. EOF is reached after `n` lines.
// let reader = io::BufReader::new(stdout);
// let expected_numbers = stream::iter_ok(0..=n);
// let read = expected_numbers.fold((reader, 0), move |(reader, i), _| {
// let done = i >= n;
// debug!("starting read from child");
// read_until(reader, b'\n', Vec::new()).and_then(move |(reader, vec)| {
// debug!("read line {} from child ({} bytes, done: {})",
// i, vec.len(), done);
// match (done, vec.len()) {
// (false, 0) => {
// Err(io::Error::new(io::ErrorKind::BrokenPipe, "broken pipe"))
// },
// (true, n) if n != 0 => {
// Err(io::Error::new(io::ErrorKind::Other, "extraneous data"))
// },
// _ => {
// let s = std::str::from_utf8(&vec).unwrap();
// let expected = format!("line {}\n", i);
// if done || s == expected {
// Ok((reader, i + 1))
// } else {
// Err(io::Error::new(io::ErrorKind::Other, "unexpected data"))
// }
// }
// }
// })
// });
//
// // Compose reading and writing concurrently.
// Box::new(write.join(read).and_then(|_| cat))
//}
#[allow(dead_code)]
fn start_server() {
let addr = ([127, 0, 0, 1], 19099).into();
let server = Server::bind(&addr)
@ -86,3 +174,7 @@ fn main() {
// Run this server for... forever!
hyper::rt::run(server);
}
fn main() {
println!("FO");
}

2
webdata/index.html

@ -96,5 +96,5 @@
( ;GM[1]FF[4]CA[UTF-8]AP[Sabaki:0.40.1]ST[2]RU[Japanese]SZ[19]HA[2]KM[6.50]PW[White]PB[Black]AW[gb][cc][dc][ec][gc][gd][ge][gf][gg][gh]AB[cb][db][eb][fb][fc][fd][pd][fe][ff][fg][fh][dp]C[C]MA[cb][cc][cd]LB[db:AX][dc:BX][dd:CX][eb:ABX123][ec:ABX123][ed:ABX123][fe:A][ff:B][fg:1][fh:2][ge:C][gf:D][gg:3][gh:4][he:E][hf:F][hg:5][hh:6]TR[fb][gb][hb]SQ[fc][gc][hc]CR[fd][gd][hd]LN[ci:di][bj:bk][bh:bj][cj:ik][bf:df][df:dh][dh:bf][ca:ce][de:db]AR[lf:if][ic:ie][jc:le] ( ;W[pp] ( ;B[pl] ;W[mp] ;B[nn] ;W[jp] ( ;B[rp] ;W[qn] ;B[rn] ;W[qm] ;B[ql] ;W[rm] ;B[rl] ;W[ro] ;B[qq] ;W[qp] ;B[sq] ;W[sp] ;B[rr] ;W[rq])( ;B[np] ;W[no] ;B[oo] ;W[mo] ;B[op] ;W[on] ;B[pn] ;W[om] ;B[po]CR[fe][ge][he]LB[ff:A][gf:C][hf:B][fg:1][gg:3][hg:2]TR[fc][gc][hc]SQ[fd][gd][hd] ( ;)( ;AB[ed])))( ;B[np] ;W[pn])( ;B[nn] ;W[pm] ;B[pl] ;W[qm] ;B[ol] ;W[ql]))( ;PL[W]AE[fi]))
</div>
</div>
<script type="text/javascript" src="/files/dist/app_c85bff7255db45d1b85c_bundle.js"></script></body>
<script type="text/javascript" src="/files/dist/app_d53e2cfa0c76b8b60920_bundle.js"></script></body>
</html>

2
webdata/main.js

@ -18,7 +18,7 @@ var app = new Vue({
el: '#app',
data: {
mouse_pos: [0, 0],
board_size_px: 800,
board_size_px: 500,
marker_mode: "x",
engine_path: 'C:/Entwicklung/git/go/Leela0110GTP/Leela0110GTP.exe',
engine_args: "-g --noponder --nobook",

Loading…
Cancel
Save