Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
c22f486a31 |
32
src/main.rs
32
src/main.rs
@ -7,6 +7,7 @@ mod paste_id;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
use std::io::{Write,Read};
|
use std::io::{Write,Read};
|
||||||
@ -192,7 +193,12 @@ impl Backend for DefaultBackend {
|
|||||||
fn upload_tcp_stream(&self, mut stream: TcpStream) -> Result<()> {
|
fn upload_tcp_stream(&self, mut stream: TcpStream) -> Result<()> {
|
||||||
let (filename, info_filename, url) = self.new_paste();
|
let (filename, info_filename, url) = self.new_paste();
|
||||||
|
|
||||||
PasteInfo::default().write(info_filename)?;
|
let paste_info = PasteInfo::default();
|
||||||
|
println!("before");
|
||||||
|
println!("toml: {}", toml::to_string(&paste_info)?);
|
||||||
|
println!("before2");
|
||||||
|
paste_info.write(info_filename)?;
|
||||||
|
println!("after");
|
||||||
|
|
||||||
let mut paste_file = File::create(&filename)?;
|
let mut paste_file = File::create(&filename)?;
|
||||||
|
|
||||||
@ -355,24 +361,26 @@ fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, upload_max_size: u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
//fn run_tcp() {
|
//fn run_tcp() {
|
||||||
fn run_tcp<T: Send + Sync + 'static>(backend: T)
|
fn run_tcp(backend: Arc<dyn Backend>)
|
||||||
where T: Backend
|
|
||||||
{
|
{
|
||||||
// Bind the server's socket
|
// Bind the server's socket
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
//let backendbla = DefaultBackend::default();
|
//let backendbla = DefaultBackend::default();
|
||||||
//let backend = &backendbla;
|
//let backend = &backendbla;
|
||||||
//let backend = backend.as_ref();
|
//let backend = backend.as_ref();
|
||||||
let backend = &backend as &'static Backend;
|
//let backend = backend.clone();
|
||||||
let listener = TcpListener::bind("127.0.0.1:12345").unwrap();
|
let host = "127.0.0.1:12345";
|
||||||
|
let listener = TcpListener::bind(host).expect("could not listen on 127.0.0.1:12345");
|
||||||
|
println!("Listening for connections on {}", &host);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match listener.accept() {
|
match listener.accept() {
|
||||||
Ok((mut stream, _addr)) => {
|
Ok((mut stream, _addr)) => {
|
||||||
|
println!("got new connection");
|
||||||
|
let backend = backend.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
backend.upload_tcp_stream(stream).is_ok(); // again we don't care about this error
|
backend.upload_tcp_stream(stream).expect("wtf");//.is_ok(); // again we don't care about this error
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
@ -383,12 +391,12 @@ fn run_tcp<T: Send + Sync + 'static>(backend: T)
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let backend = Box::new(DefaultBackend::default());
|
let backend: Arc<Backend> = Arc::new(DefaultBackend::default());
|
||||||
//let tcp_backend = DefaultBackend::default();
|
run_tcp(backend);
|
||||||
//run_tcp(tcp_backend);
|
|
||||||
//run_tcp();
|
//run_tcp();
|
||||||
rocket().manage(backend as Box<Backend + 'static>).launch();
|
let rocket_backend = Box::new(DefaultBackend::default());
|
||||||
|
rocket().manage(rocket_backend as Box<Backend + 'static>).launch();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user