diff options
Diffstat (limited to 'stdlib/source/lux/world/net')
-rw-r--r-- | stdlib/source/lux/world/net/tcp.jvm.lux | 40 | ||||
-rw-r--r-- | stdlib/source/lux/world/net/udp.jvm.lux | 32 |
2 files changed, 36 insertions, 36 deletions
diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux index 0a109d04c..f279a0873 100644 --- a/stdlib/source/lux/world/net/tcp.jvm.lux +++ b/stdlib/source/lux/world/net/tcp.jvm.lux @@ -11,24 +11,24 @@ [host]) [//]) -(host;import java.lang.AutoCloseable +(host;import java/lang/AutoCloseable (close [] #io #try void)) -(host;import java.io.Flushable +(host;import java/io/Flushable (flush [] #io #try void)) -(host;import java.io.InputStream +(host;import java/io/InputStream (read [(Array byte) int int] #io #try int)) -(host;import java.io.OutputStream +(host;import java/io/OutputStream (write [(Array byte) int int] #io #try void)) -(host;import java.net.Socket +(host;import java/net/Socket (new [String int] #io #try) (getInputStream [] #io #try InputStream) (getOutputStream [] #io #try OutputStream)) -(host;import java.net.ServerSocket +(host;import java/net/ServerSocket (new [int] #io #try) (accept [] #io #try Socket)) @@ -45,31 +45,31 @@ (let [in (get@ #in (@repr self))] (P;future (do (e;ErrorT io;Monad<IO>) - [bytes-read (InputStream.read [data (nat-to-int offset) (nat-to-int length)] - in)] + [bytes-read (InputStream::read [data (nat-to-int offset) (nat-to-int length)] + in)] (wrap (int-to-nat bytes-read)))))) (def: #export (write data offset length self) (let [out (get@ #out (@repr self))] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (OutputStream.write [data (nat-to-int offset) (nat-to-int length)] - out)] - (Flushable.flush [] out))))) + [_ (OutputStream::write [data (nat-to-int offset) (nat-to-int length)] + out)] + (Flushable::flush [] out))))) (def: #export (close self) (let [(^open) (@repr self)] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (AutoCloseable.close [] in) - _ (AutoCloseable.close [] out)] - (AutoCloseable.close [] socket))))) + [_ (AutoCloseable::close [] in) + _ (AutoCloseable::close [] out)] + (AutoCloseable::close [] socket))))) (def: (tcp-client socket) (-> Socket (io;IO (e;Error TCP))) (do (e;ErrorT io;Monad<IO>) - [input (Socket.getInputStream [] socket) - output (Socket.getOutputStream [] socket)] + [input (Socket::getInputStream [] socket) + output (Socket::getOutputStream [] socket)] (wrap (@opaque {#socket socket #in input #out output})))) @@ -78,7 +78,7 @@ (-> //;Address //;Port (T;Task TCP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (Socket.new [address (nat-to-int port)])] + [socket (Socket::new [address (nat-to-int port)])] (tcp-client socket)))) (def: (await-server-release client-channel server) @@ -91,7 +91,7 @@ #;None (P;future (do io;Monad<IO> - [_ (AutoCloseable.close [] server)] + [_ (AutoCloseable::close [] server)] (wrap []))) ## A client was generated. @@ -103,14 +103,14 @@ (-> //;Port (T;Task (frp;Channel TCP))) (P;future (do (e;ErrorT io;Monad<IO>) - [server (ServerSocket.new [(nat-to-int port)]) + [server (ServerSocket::new [(nat-to-int port)]) #let [output (frp;channel TCP) _ (: (P;Promise Bool) (P;future (loop [tail output] (do io;Monad<IO> [?client (do (e;ErrorT io;Monad<IO>) - [socket (ServerSocket.accept [] server)] + [socket (ServerSocket::accept [] server)] (tcp-client socket))] (case ?client (#e;Error error) diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux index 139ed4f49..3bb94e112 100644 --- a/stdlib/source/lux/world/net/udp.jvm.lux +++ b/stdlib/source/lux/world/net/udp.jvm.lux @@ -14,24 +14,24 @@ [host]) [//]) -(host;import java.lang.AutoCloseable +(host;import java/lang/AutoCloseable (close [] #io #try void)) -(host;import java.io.Flushable +(host;import java/io/Flushable (flush [] #io #try void)) -(host;import java.net.InetAddress +(host;import java/net/InetAddress (#static getAllByName [String] #io #try (Array InetAddress)) (getHostAddress [] String)) -(host;import java.net.DatagramPacket +(host;import java/net/DatagramPacket (new #as new|send [(Array byte) int int InetAddress int]) (new #as new|receive [(Array byte) int int]) (getAddress [] InetAddress) (getPort [] int) (getLength [] int)) -(host;import java.net.DatagramSocket +(host;import java/net/DatagramSocket (new #as new|client [] #io #try) (new #as new|server [int] #io #try) (receive [DatagramPacket] #io #try void) @@ -47,7 +47,7 @@ (def: (resolve address) (-> //;Address (io;IO (e;Error InetAddress))) (do (e;ErrorT io;Monad<IO>) - [addresses (InetAddress.getAllByName [address])] + [addresses (InetAddress::getAllByName [address])] (: (io;IO (e;Error InetAddress)) (case (array;size addresses) +0 (io;io (ex;throw Cannot-Resolve-Address address)) @@ -60,14 +60,14 @@ (def: #export (read data offset length self) (-> Blob Nat Nat UDP (T;Task [Nat //;Address //;Port])) (let [(^open) (@repr self) - packet (DatagramPacket.new|receive [data (nat-to-int offset) (nat-to-int length)])] + packet (DatagramPacket::new|receive [data (nat-to-int offset) (nat-to-int length)])] (P;future (do (e;ErrorT io;Monad<IO>) - [_ (DatagramSocket.receive [packet] socket) - #let [bytes-read (int-to-nat (DatagramPacket.getLength [] packet))]] + [_ (DatagramSocket::receive [packet] socket) + #let [bytes-read (int-to-nat (DatagramPacket::getLength [] packet))]] (wrap [bytes-read - (|> packet (DatagramPacket.getAddress []) (InetAddress.getHostAddress [])) - (int-to-nat (DatagramPacket.getPort [] packet))]))))) + (|> packet (DatagramPacket::getAddress []) (InetAddress::getHostAddress [])) + (int-to-nat (DatagramPacket::getPort [] packet))]))))) (def: #export (write address port data offset length self) (-> //;Address //;Port Blob Nat Nat UDP (T;Task Unit)) @@ -75,26 +75,26 @@ (do (e;ErrorT io;Monad<IO>) [address (resolve address) #let [(^open) (@repr self)]] - (DatagramSocket.send (DatagramPacket.new|send [data (nat-to-int offset) (nat-to-int length) address (nat-to-int port)]) - socket)))) + (DatagramSocket::send (DatagramPacket::new|send [data (nat-to-int offset) (nat-to-int length) address (nat-to-int port)]) + socket)))) (def: #export (close self) (-> UDP (T;Task Unit)) (let [(^open) (@repr self)] (P;future - (AutoCloseable.close [] socket)))) + (AutoCloseable::close [] socket)))) (def: #export (client _) (-> Unit (T;Task UDP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (DatagramSocket.new|client [])] + [socket (DatagramSocket::new|client [])] (wrap (@opaque (#socket socket)))))) (def: #export (server port) (-> //;Port (T;Task UDP)) (P;future (do (e;ErrorT io;Monad<IO>) - [socket (DatagramSocket.new|server [(nat-to-int port)])] + [socket (DatagramSocket::new|server [(nat-to-int port)])] (wrap (@opaque (#socket socket)))))) ) |