aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/world/net/tcp.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/world/net/tcp.lux50
1 files changed, 26 insertions, 24 deletions
diff --git a/stdlib/source/lux/world/net/tcp.lux b/stdlib/source/lux/world/net/tcp.lux
index a0fa13c8a..d9011a5cb 100644
--- a/stdlib/source/lux/world/net/tcp.lux
+++ b/stdlib/source/lux/world/net/tcp.lux
@@ -36,39 +36,41 @@
[write //.can-write]
[close //.can-close])))))
-(with-expansions [<for-jvm> (as-is (import: java/lang/AutoCloseable
+(with-expansions [<for-jvm> (as-is (import: #long java/lang/String)
+
+ (import: #long java/lang/AutoCloseable
(close [] #io #try void))
- (import: java/io/Flushable
+ (import: #long java/io/Flushable
(flush [] #io #try void))
- (import: java/io/InputStream
+ (import: #long java/io/InputStream
(read [[byte] int int] #io #try int))
- (import: java/io/OutputStream
+ (import: #long java/io/OutputStream
(write [[byte] int int] #io #try void))
- (import: java/net/Socket
- (new [String int] #io #try)
- (getInputStream [] #try InputStream)
- (getOutputStream [] #try OutputStream))
+ (import: #long java/net/Socket
+ (new [java/lang/String int] #io #try)
+ (getInputStream [] #try java/io/InputStream)
+ (getOutputStream [] #try java/io/OutputStream))
- (import: java/net/ServerSocket
+ (import: #long java/net/ServerSocket
(new [int] #io #try)
- (accept [] #io #try Socket))
+ (accept [] #io #try java/net/Socket))
(def: (tcp socket)
- (-> Socket (Error (TCP IO)))
+ (-> java/net/Socket (Error (TCP IO)))
(do error.monad
- [input (Socket::getInputStream socket)
- output (Socket::getOutputStream socket)]
+ [input (java/net/Socket::getInputStream socket)
+ output (java/net/Socket::getOutputStream socket)]
(wrap (: (TCP IO)
(structure (def: read
(//.can-read
(function (read size)
(do (error.with io.monad)
[#let [data (binary.create size)]
- bytes-read (InputStream::read data +0 (.int size) input)]
+ bytes-read (java/io/InputStream::read data +0 (.int size) input)]
(wrap [(.nat bytes-read)
data])))))
@@ -76,33 +78,33 @@
(//.can-write
(function (write data)
(do (error.with io.monad)
- [_ (OutputStream::write data +0 (.int (binary.size data))
- output)]
- (Flushable::flush output)))))
+ [_ (java/io/OutputStream::write data +0 (.int (binary.size data))
+ output)]
+ (java/io/Flushable::flush output)))))
(def: close
(//.can-close
(function (close _)
(do (error.with io.monad)
- [_ (AutoCloseable::close input)
- _ (AutoCloseable::close output)]
- (AutoCloseable::close socket))))))))))
+ [_ (java/lang/AutoCloseable::close input)
+ _ (java/lang/AutoCloseable::close output)]
+ (java/lang/AutoCloseable::close socket))))))))))
(def: #export (client address port)
(-> //.Address //.Port (IO (Error (TCP IO))))
(do (error.with io.monad)
- [socket (Socket::new address (.int port))]
+ [socket (java/net/Socket::new address (.int port))]
(io.io (tcp socket))))
(def: #export (server port)
(-> //.Port (IO (Error [(Resolver Any)
(Channel (TCP IO))])))
(do (error.with io.monad)
- [server (ServerSocket::new (.int port))
+ [server (java/net/ServerSocket::new (.int port))
#let [[close-signal close-resolver] (: [(Promise Any) (Resolver Any)]
(promise.promise []))
_ (promise.await (function (_ _)
- (AutoCloseable::close server))
+ (java/lang/AutoCloseable::close server))
close-signal)
[output sink] (: [(Channel (TCP IO)) (Sink (TCP IO))]
(frp.channel []))
@@ -111,7 +113,7 @@
(loop [_ []]
(do io.monad
[?client (do (error.with io.monad)
- [socket (ServerSocket::accept server)]
+ [socket (java/net/ServerSocket::accept server)]
(io.io (tcp socket)))]
(case ?client
(#error.Failure error)