speedlim.ose
/#/ Store a socket for sending udp to localhost on port 10001.
/,/s/127.0.0.1
/,/i/10001
/!/udp/sock/connect
/@/udp/sock/accept
/#/ Store a socket for sending udp to localhost on port 10002.
/,/s/127.0.0.1
/,/i/10002
/!/udp/sock/connect
/@/udp/sock/reject
/,/i/0
/@/count
/,/i/5
/@/n
/#/ ############################################################
/#/ /@/speedlim
/#/
/#/ Send every nth packet to /$/udp/sock/accept, and the rest
/#/ to /$/udp/sock/reject. Also, stick the count in the bundle
/#/ before sending.
/#/ ############################################################
/#/ Read from the UDP socket.
/'/!/udp/recv
/#/ Drop the sender address and port
/'/!/2drop
/#/ Get the count and assign it to the bundle that just arrived.
/'/$/count
/'/,/s//speedlim/count
/'/!/assign
/#/ Send to /udp/sock/accept if /count % /n is 0, or
/#/ /udp/sock/reject otherwise.
/!/make/bundle
/'/$/udp/sock/reject
/!/push
/!/make/bundle
/'/$/udp/sock/accept
/!/push
/'/$/n
/'/$/count
/'/!/mod
/,/i/0
/'/!/eql
/'/!/if
/#/ /if calls /exec which leaves the env on the stack.
/'/!/drop
/#/ Send the bundle.
/'/!/udp/send
/#/ Increment the count.
/'/$/count
/,/i/1
/'/!/add
/'/@/count
/!/bundle/all
/@/speedlim
/#/ Listen for UDP packets on port 10000, and call /!/speedlim
/#/ when they arrive.
/'/!/speedlim
/!/bundle/all
/,/i/10000
/!/udp/receive