aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/world/net/tcp.jvm.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/world/net/tcp.jvm.lux76
1 files changed, 38 insertions, 38 deletions
diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux
index f279a0873..3d71e85f8 100644
--- a/stdlib/source/lux/world/net/tcp.jvm.lux
+++ b/stdlib/source/lux/world/net/tcp.jvm.lux
@@ -1,4 +1,4 @@
-(;module:
+(.module:
lux
(lux (control monad)
(concurrency ["P" promise]
@@ -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))
@@ -43,31 +43,31 @@
(def: #export (read data offset length self)
(let [in (get@ #in (@repr self))]
- (P;future
- (do (e;ErrorT io;Monad<IO>)
+ (P.future
+ (do (e.ErrorT io.Monad<IO>)
[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>)
+ (P.future
+ (do (e.ErrorT io.Monad<IO>)
[_ (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>)
+ (P.future
+ (do (e.ErrorT io.Monad<IO>)
[_ (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>)
+ (-> Socket (io.IO (e.Error TCP)))
+ (do (e.ErrorT io.Monad<IO>)
[input (Socket::getInputStream [] socket)
output (Socket::getOutputStream [] socket)]
(wrap (@opaque {#socket socket
@@ -75,55 +75,55 @@
#out output}))))
(def: #export (client address port)
- (-> //;Address //;Port (T;Task TCP))
- (P;future
- (do (e;ErrorT io;Monad<IO>)
+ (-> //.Address //.Port (T.Task TCP))
+ (P.future
+ (do (e.ErrorT io.Monad<IO>)
[socket (Socket::new [address (nat-to-int port)])]
(tcp-client socket))))
(def: (await-server-release client-channel server)
- (-> (frp;Channel TCP) ServerSocket (P;Promise Unit))
- (do P;Monad<Promise>
+ (-> (frp.Channel TCP) ServerSocket (P.Promise Unit))
+ (do P.Monad<Promise>
[outcome client-channel]
(case outcome
## Channel has been closed.
## Must close associated server.
- #;None
- (P;future
- (do io;Monad<IO>
+ #.None
+ (P.future
+ (do io.Monad<IO>
[_ (AutoCloseable::close [] server)]
(wrap [])))
## A client was generated.
## Nothing to be done...
- (#;Some _)
+ (#.Some _)
(wrap []))))
(def: #export (server port)
- (-> //;Port (T;Task (frp;Channel TCP)))
- (P;future
- (do (e;ErrorT io;Monad<IO>)
+ (-> //.Port (T.Task (frp.Channel TCP)))
+ (P.future
+ (do (e.ErrorT io.Monad<IO>)
[server (ServerSocket::new [(nat-to-int port)])
- #let [output (frp;channel TCP)
- _ (: (P;Promise Bool)
- (P;future
+ #let [output (frp.channel TCP)
+ _ (: (P.Promise Bool)
+ (P.future
(loop [tail output]
- (do io;Monad<IO>
- [?client (do (e;ErrorT io;Monad<IO>)
+ (do io.Monad<IO>
+ [?client (do (e.ErrorT io.Monad<IO>)
[socket (ServerSocket::accept [] server)]
(tcp-client socket))]
(case ?client
- (#e;Error error)
- (frp;close tail)
+ (#e.Error error)
+ (frp.close tail)
- (#e;Success client)
+ (#e.Success client)
(do @
- [?tail' (frp;write client tail)]
+ [?tail' (frp.write client tail)]
(case ?tail'
- #;None
+ #.None
(wrap true)
- (#;Some tail')
+ (#.Some tail')
(exec (await-server-release tail' server)
(recur tail')))))))))]]
(wrap output))))