Skip to content

Commit

Permalink
FIX: missing messages in UDP server
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 19, 2022
1 parent 40632bc commit c5e159b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/core/p-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ enum Transport_Types {
//Print("(max read length %d)", sock->length);
result = OS_DO_DEVICE(sock, RDC_READ); // recv can happen immediately
if (result < 0) Trap_Port(RE_READ_ERROR, port, sock->error);
VAL_TAIL(arg) += sock->actual;
break;

case A_WRITE:
Expand Down
40 changes: 40 additions & 0 deletions src/tests/test-udp-client.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Rebol [
Title: "Test UDP client"
File: %test-udp-client.r3
Note: https://github.com/Oldes/Rebol-issues/issues/1803
]

; start test UDP server...
launch probe to-real-file %test-udp-server.r3

; wait some time for server to boot...
wait 0:0:0.1

stdout: system/ports/output

; open port for output...
port: open udp://127.0.0.1:1189
port/awake: func[event][
print ["[UDP Client] event:" event/type]
;; console output is buffered and so messages could come out of order;
;; to prevent it, just use the `flush`!
flush stdout
true
]
; wait for port to be opened (required on Windows!)...
wait port

write-udp: func[msg [string!]][
print ["[UDP Client] sending:" as-yellow mold msg]
flush stdout ;= flush console buffer!
write port msg
]
write-udp "Hello"
write-udp "Rebol"
wait 1 ;= pretending some work here...
write-udp "I'm done!"
write-udp "quit"

either system/options/script [
ask as-red "CLIENT DONE"
][ print as-red "CLIENT DONE" wait 0.5]
13 changes: 9 additions & 4 deletions src/tests/test-udp-server.r3
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ udp-server: try/except [open udp://:1189][
print as-purple "Failed to listen on UDP port 1189!"
quit
]
stdout: system/ports/output

udp-server/awake: func [event] [
print ["UDP event:" as-yellow event/type]
print ["[UDP Server] event:" event/type]
;; console output is buffered and so messages could come out of order;
;; to prevent it, just use the `flush`!
flush stdout
true
]

forever [
wait read udp-server
str: to string! udp-server/data
print ["UDP input:" as-green mold str]
print ["[UDP Server] received:" as-green mold str]
flush stdout ;= flush console buffer!
if str = "quit" [close udp-server break]
clear udp-server/data
]
print as-red "SERVER DONE"
wait 0:0:1
print as-red "SERVER DONE"
23 changes: 0 additions & 23 deletions src/tests/test-udp.r3

This file was deleted.

0 comments on commit c5e159b

Please sign in to comment.