Skip to content

Commit

Permalink
non blocking udp read (we still block on keypresses)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Jul 28, 2024
1 parent fa92c0a commit 3c27b1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/teeworlds_asmr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ section .data
KEY_RETURN equ 13
AF_INET equ 0x2
SOCK_DGRAM equ 0x2
MSG_DONTWAIT equ 64

; application constants
HEX_TABLE db "0123456789ABCDEF", 0
Expand Down Expand Up @@ -131,6 +132,8 @@ section .data
l_s_blocking_read equ $ - s_blocking_read
s_received_bytes db "[udp] received bytes: "
l_s_received_bytes equ $ - s_received_bytes
s_udp_error db "[udp] error: "
l_s_udp_error equ $ - s_udp_error
s_packer_size db "[packer] amount of bytes packed: "
l_s_packer_size equ $ - s_packer_size

Expand Down Expand Up @@ -440,6 +443,7 @@ gametick:
; gametick
;
; main gameloop using recursion
call pump_network
call keypresses
jmp gametick

Expand Down
12 changes: 12 additions & 0 deletions src/udp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,31 @@ recv_udp:
movzx rdi, byte [socket] ; then only set the lowest byte
lea rsi, udp_recv_buf
mov rdx, NET_MAX_PACKETSIZE
; flags
xor r10, r10
mov r10, MSG_DONTWAIT
lea r8, udp_srv_addr
lea r9, max_sockaddr_read_size
syscall
mov [udp_read_len], rax

; error checking
test rax, rax
; if recvfrom returned negative
; we do not process the udp payload
js .recv_udp_error

; debug print
print s_received_bytes
mov rax, [udp_read_len]
call print_uint32
call print_newline

ret
.recv_udp_error:
print s_udp_error
call print_newline
ret

send_udp:
; send_udp [rax] [rdi]
Expand Down

0 comments on commit 3c27b1d

Please sign in to comment.