Skip to content

Commit cff85d5

Browse files
Merge pull request #9 from SpontanCombust/dev
2 parents a5a0fd9 + a81a77c commit cff85d5

File tree

5 files changed

+62
-19
lines changed

5 files changed

+62
-19
lines changed

.github/workflows/check-build.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,29 @@ env:
1111

1212
jobs:
1313
build:
14-
runs-on: windows-latest
14+
strategy:
15+
matrix:
16+
include:
17+
- os: ubuntu-latest
18+
target: x86_64-unknown-linux-gnu
19+
- os: windows-latest
20+
target: x86_64-pc-windows-msvc
1521

22+
runs-on: ${{ matrix.os }}
1623
steps:
1724
- name: Checkout
1825
uses: actions/checkout@v2
1926
- name: Use Rust stable
2027
uses: actions-rs/toolchain@v1
2128
with:
2229
toolchain: stable
23-
target: x86_64-pc-windows-msvc
30+
target: ${{ matrix.target }}
2431
override: true
32+
2533
- name: Build with Cargo
2634
uses: actions-rs/cargo@v1
2735
with:
2836
command: build
29-
args: --release --target=x86_64-pc-windows-msvc
37+
args: --release --target ${{ matrix.target }}
3038
- name: Run tests
3139
run: cargo test --verbose

.github/workflows/draft-release.yml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,59 @@ env:
99

1010
jobs:
1111
build:
12-
runs-on: windows-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- os: ubuntu-latest
16+
target: x86_64-unknown-linux-gnu
17+
exec_name: rw3d_cli
18+
- os: windows-latest
19+
target: x86_64-pc-windows-msvc
20+
exec_name: rw3d_cli.exe
1321

22+
runs-on: ${{ matrix.os }}
1423
steps:
1524
- name: Checkout
1625
uses: actions/checkout@v2
1726
- name: Use Rust stable
1827
uses: actions-rs/toolchain@v1
1928
with:
2029
toolchain: stable
21-
target: x86_64-pc-windows-msvc
30+
target: ${{ matrix.target }}
2231
override: true
2332
- name: Build with Cargo
2433
uses: actions-rs/cargo@v1
2534
with:
2635
command: build
27-
args: --package rw3d_cli --release --target=x86_64-pc-windows-msvc
36+
args: --package rw3d_cli --release --target ${{ matrix.target }}
37+
2838
- name: Zip the executable
2939
uses: papeloto/action-zip@v1
3040
with:
31-
files: "target/x86_64-pc-windows-msvc/release/rw3d_cli.exe"
32-
dest: "rw3d_cli_${{ github.ref_name }}.zip"
33-
- name: Create draft release
41+
files: "target/${{ matrix.target }}/release/${{ matrix.exec_name }}"
42+
dest: "rw3d_cli-${{ github.ref_name }}-${{ matrix.target }}.zip"
43+
- name: Upload artifacts
44+
uses: actions/upload-artifact@v2
45+
with:
46+
name: ${{ matrix.target }}
47+
path: "*.zip"
48+
if-no-files-found: error
49+
50+
publish:
51+
runs-on: ubuntu-latest
52+
needs: build
53+
if: success()
54+
55+
steps:
56+
- name: Download artifacts
57+
uses: actions/download-artifact@v2
58+
59+
- name: Prepare artifact list for release action
60+
run: echo "ARTIFACTS=$(echo $(find . -iname "*.zip") | sed "s/ /,/g")" >> $GITHUB_ENV
61+
- name: Create draft release on GitHub
3462
uses: ncipollo/release-action@v1
3563
with:
36-
artifacts: "rw3d_cli_${{ github.ref_name }}.zip"
64+
artifacts: "${{ env.ARTIFACTS }}"
3765
draft: true
66+
allowUpdates: true
3867
generateReleaseNotes: true

crates/mock-server/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ServiceMap = HashMap<MessageId, Box<dyn Service + Send + Sync>>;
1313

1414
impl MockWitcherServer {
1515
const LISTEN_INTERVAL_MILLIS: u64 = 500;
16-
const PEEK_INTERVAL_MILLIS: u64 = 100;
16+
const READ_TIMEOUT_MILLIS: u64 = 100;
1717

1818
pub fn new() -> anyhow::Result<Arc<Self>> {
1919
let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, WitcherConnection::GAME_PORT))?;
@@ -64,9 +64,13 @@ impl MockWitcherServer {
6464
Ok((socket, addr)) => {
6565
println!("Client connected on address {}", addr);
6666

67+
socket.set_nonblocking(false).unwrap();
68+
socket.set_read_timeout(Some(std::time::Duration::from_millis(Self::READ_TIMEOUT_MILLIS))).unwrap();
6769
let self_clone = self.clone();
68-
std::thread::spawn(move || -> anyhow::Result<()> {
69-
self_clone.serve_for(socket)
70+
std::thread::spawn(move || {
71+
if let Err(err) = self_clone.serve_for(socket) {
72+
eprintln!("Server abruptly lost connection to the client: {}", err);
73+
}
7074
});
7175
}
7276
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {
@@ -89,12 +93,11 @@ impl MockWitcherServer {
8993
service.accept_packet(packet, &mut client_socket);
9094
}
9195
}
92-
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {
93-
std::thread::sleep(std::time::Duration::from_millis(Self::PEEK_INTERVAL_MILLIS));
94-
},
9596
Err(err) => {
96-
eprintln!("{}", err);
97-
break Err(err.into());
97+
if !matches!(err.kind(), std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut) {
98+
99+
break Err(err.into());
100+
}
98101
}
99102
}
100103
}

crates/net-client/tests/integration.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ fn integration_test() -> anyhow::Result<()> {
1616
Ok(())
1717
});
1818

19+
// wait for the server to set up
20+
std::thread::sleep(std::time::Duration::from_millis(100));
21+
1922
let conn = WitcherConnection::connect_timeout(Ipv4Addr::LOCALHOST.into(), Duration::from_secs(1))?;
2023
let client = WitcherClient::new(conn);
2124
client.start()?;

crates/net/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl WitcherConnection {
7676
Ok(peeked) => {
7777
Ok(peeked >= peek_buffer.len())
7878
}
79-
Err(err) if matches!(err.kind(), std::io::ErrorKind::TimedOut) => {
79+
Err(err) if matches!(err.kind(), std::io::ErrorKind::TimedOut | std::io::ErrorKind::WouldBlock) => {
8080
Ok(false)
8181
},
8282
Err(err) => {

0 commit comments

Comments
 (0)