From 3b34c44084dca767fc389b2704aeb4209bb9aa6f Mon Sep 17 00:00:00 2001 From: Huanzo Date: Mon, 15 Mar 2021 18:00:20 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + Cargo.lock | 141 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 ++++ drone.yml | 9 +++ src/main.rs | 11 ++++ src/pixelflut.rs | 67 ++++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 drone.yml create mode 100644 src/main.rs create mode 100644 src/pixelflut.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..fcc2905 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,141 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "libc" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" + +[[package]] +name = "lock_api" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "pixelrush" +version = "0.1.0" +dependencies = [ + "r2d2", +] + +[[package]] +name = "r2d2" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" +dependencies = [ + "log", + "parking_lot", + "scheduled-thread-pool", +] + +[[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + +[[package]] +name = "scheduled-thread-pool" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" +dependencies = [ + "parking_lot", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9e48003 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "pixelrush" +version = "0.1.0" +authors = ["Huanzo "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +r2d2 = "*" diff --git a/drone.yml b/drone.yml new file mode 100644 index 0000000..97849ec --- /dev/null +++ b/drone.yml @@ -0,0 +1,9 @@ +kind: pipeline +type: docker +name: check + +steps: +- name: Cargo check + image: rust:latest + commands: + - cargo check diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..585df70 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,11 @@ +mod pixelflut; + +use pixelflut::*; + +fn main() -> Result<(), std::io::Error>{ + let manager = PixelflutConnectionManager::new("localhost:1234")?; + let pool = r2d2::Pool::builder() + .max_size(15) + .build(manager).expect("Could not initialize connection pool"); + Ok(()) +} diff --git a/src/pixelflut.rs b/src/pixelflut.rs new file mode 100644 index 0000000..f06b07e --- /dev/null +++ b/src/pixelflut.rs @@ -0,0 +1,67 @@ +use r2d2::ManageConnection; +use std::{io::Error, net::{SocketAddr, TcpStream}}; +use std::io::Write; + +pub struct PixelflutConnectionManager { + addr: SocketAddr +} + +pub struct PixelflutConnection { + stream: TcpStream +} + +impl PixelflutConnectionManager { + pub fn new(addr: &str) -> Result { + let addr: SocketAddr = match addr.parse() { + Ok(addr) => addr, + Err(e) => panic!("Error in parsing the socket address: {}", e) + }; + Ok(Self {addr}) + } + + fn get_connection(&self) -> Result { + let stream = TcpStream::connect(self.addr)?; + Ok(PixelflutConnection {stream}) + } + +} + +pub struct Rgba(pub u32); + +impl From for Rgba { + fn from(a: u32) -> Self { + Self(a) + } +} + +impl PixelflutConnection { + #[inline] + pub fn new(addr: SocketAddr) -> Result { + let stream = TcpStream::connect(addr)?; + Ok(Self {stream}) + } + + pub fn set(&mut self, x: usize, y: usize, c: impl Into) { + let msg = format!("PX {} {} {}\n", x,y,12); + self.stream.write(&msg[..].as_bytes()); + } +} + + +impl ManageConnection for PixelflutConnectionManager { + type Connection = PixelflutConnection; + type Error = Error; + + fn connect(&self) -> Result { + self.get_connection() + } + + fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> { + todo!() + } + + fn has_broken(&self, conn: &mut Self::Connection) -> bool { + false + } + +}