aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/world/net/udp.jvm.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/world/net/udp.jvm.lux')
-rw-r--r--stdlib/source/lux/world/net/udp.jvm.lux20
1 files changed, 9 insertions, 11 deletions
diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux
index 842f1c969..f27ca1c5e 100644
--- a/stdlib/source/lux/world/net/udp.jvm.lux
+++ b/stdlib/source/lux/world/net/udp.jvm.lux
@@ -20,7 +20,7 @@
[platform
[compiler
["." host]]]]
- ["." // (#+ Location)])
+ ["." // (#+ Location Can-Read Can-Write Can-Close)])
(import: java/lang/AutoCloseable
(close [] #io #try void))
@@ -56,23 +56,21 @@
(ex.report ["Address" address]))
(signature: #export (UDP !)
- (: (-> Nat (! (Error [Nat Location (Dirty Binary)])))
+ (: (Can-Read ! [Nat Location (Dirty Binary)])
read)
- (: (-> Location Binary (! (Error Any)))
+ (: (Can-Write ! [Location Binary])
write)
- (: (-> Any (! (Error Any)))
+ (: (Can-Close !)
close))
(def: #export (async udp)
(-> (UDP IO) (UDP Promise))
- (`` (structure (def: read (|>> (:: udp read) promise.future))
-
- (def: (write location data)
- (promise.future (:: udp write location data)))
-
- (def: close (|>> (:: udp close) promise.future)))))
+ (`` (structure (~~ (do-template [<name>]
+ [(def: <name> (|>> (:: udp <name>) promise.future))]
+
+ [read] [write] [close])))))
(`` (for {(~~ (static host.jvm))
(as-is (def: (resolve address)
@@ -98,7 +96,7 @@
#//.port (.nat (DatagramPacket::getPort packet))}
(taint data)]))))
- (def: (write location data)
+ (def: (write [location data])
(do io.Monad<Process>
[address (resolve (get@ #//.address location))]
(DatagramSocket::send (DatagramPacket::new|send data +0 (.int (binary.size data)) address (.int (get@ #//.port location)))