Skip to content

Commit

Permalink
Added connect timeout based on W5100 RTR value for Uthernet2
Browse files Browse the repository at this point in the history
  • Loading branch information
univta0001 committed Jun 22, 2024
1 parent a314c4b commit fa98f15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions a2stream/a2stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ To prepare an .a2stream file for streaming:
Create a header-less .raw file with 22050Hz mono 32-bit-float PCM data (e.g. with Audacity)
Generate an .a2stream file from the .raw file with gena2stream (source code)
Put a standard 16kB .dhgr file beside the .raw file for custom cover art (optional)
Use b2d <24-bit bmp> -d9
Use the option to -p switch the visualization from level meter to progress bar
Put the .a2stream file onto any HTTP (not HTTPS) server
Run a simple local HTTP server on Windows
Run the HTTP File Server and drop the file you want to stream in its Virtual File System
Run a simple local HTTP server on Linux
cd to the directory containing the file you want to stream and enter python -m SimpleHTTPServer or python3 -m http.server depending on the Python version you want to use

Extract audio
ffmpeg -i Sample.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 Sample.mp3
12 changes: 10 additions & 2 deletions emulator/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::video::Video;
use std::io::ErrorKind;
use std::io::{Read, Write};
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpListener, TcpStream, ToSocketAddrs};
use std::time::Duration;

#[cfg(feature = "serde_support")]
use crate::marshal::{as_hex, from_hex_32k};
Expand Down Expand Up @@ -760,9 +761,16 @@ impl Uthernet2 {
IpAddr::V4(Ipv4Addr::new(dest[0], dest[1], dest[2], dest[3])),
port,
);
u2_debug!("Connect Socket on #{i} to {sock_addr:?} ...");
let rtr_bytes = [self.mem[W5100_RTR0], self.mem[W5100_RTR1]];
let rtr = u16::from_be_bytes(rtr_bytes) as u64;

if let Ok(stream) = TcpStream::connect(sock_addr) {
u2_debug!(
"Connect Socket on #{i} to {sock_addr:?} with timeout = {} µs ...",
rtr * 100
);

if let Ok(stream) = TcpStream::connect_timeout(&sock_addr, Duration::from_micros(rtr * 100))
{
u2_debug!("Connect Socket on #{i} to {sock_addr:?} - OK");
stream
.set_nonblocking(true)
Expand Down

0 comments on commit fa98f15

Please sign in to comment.