Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mac m1 tests pass with a key sleep. #23

Merged
merged 10 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
name: Run tests
name: Github Actions
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v1

- name: Cache choosenim
id: cache-choosenim
uses: actions/cache@v1
with:
path: ~/.choosenim
key: ${{ runner.os }}-choosenim-stable

- name: Cache nimble
id: cache-nimble
uses: actions/cache@v1
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble-stable
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: jiro4989/setup-nim-action@v1

- run: nimble test -y
- run: nimble test --gc:orc -y
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<img src="docs/nettyBanner.png">

# Netty - reliable UDP connection for Nim.

`nimble install netty`

![Github Actions](https://github.com/treeform/netty/workflows/Github%20Actions/badge.svg)

Netty is a reliable connection over UDP aimed at games. Normally UDP packets can get duplicated, dropped, or come out of order. Netty makes sure packets are not duplicated, re-sends them if they get dropped, and all packets come in order. UDP packets might also get split if they are above 512 bytes and also can fail to be sent if they are bigger than 1-2k. Netty breaks up big packets and sends them in pieces making sure each piece comes reliably in order. Finally sometimes it's impossible for two clients to communicate direclty with TCP because of NATs, but Netty provides hole punching which allows them to connect.

### Documentation

API reference: https://nimdocs.com/treeform/netty

## Is Netty a implementation of TCP?

TCP is really bad for short latency sensitive messages. TCP was designed for throughput (downloading files) not latency (games). Netty will resend stuff faster than TCP, Netty will not buffer and you also get nat punch-through (which TCP does not have). Netty is basically "like TCP but for games". You should not be using Netty if you are will be sending large mount of data. By default Netty is capped at 250K of data in flight.
Expand Down
Binary file added docs/nettyBanner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/netty.nim
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func deleteAckedParts(reactor: Reactor) =

proc readParts(reactor: Reactor) =
var
buf = newStringOfCap(reactor.debug.maxUdpPacket)
buf = newStringOfCap(reactor.debug.maxUdpPacket + headerSize)
host: string
port: Port

Expand All @@ -279,6 +279,8 @@ proc readParts(reactor: Reactor) =
buf, reactor.debug.maxUdpPacket + headerSize, host, port
)
except:
when defined(nettyMagicSleep):
sleep(1)
break

let address = initAddress(host, port.int)
Expand Down
3 changes: 3 additions & 0 deletions tests/config.nims
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
--path:"../src"
# On macOS localhost writes take longer, so sleep in strategic places
# to make it like Windows and Linux.
--define:"nettyMagicSleep"
47 changes: 0 additions & 47 deletions tests/test-output.txt

This file was deleted.

Loading