-
-
Save pzel/ac2cfddfff72c435e2276ea5b4da27cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use "net" | |
actor Main | |
new create(env: Env) => | |
try | |
let a = env.root as AmbientAuth | |
TCPListener.ip4(a, recover Listen("hello", a, env) end, | |
"0.0.0.0", "9001") | |
end | |
class Listen is TCPListenNotify | |
let _auth: AmbientAuth | |
let _worker_name: String | |
let _env: Env | |
var _host: String = "" | |
var _service: String = "" | |
new iso create(name: String, auth: AmbientAuth, env: Env) => | |
_auth = auth | |
_worker_name = name | |
_env = env | |
fun ref listening(listen: TCPListener ref) => | |
try | |
(_host, _service) = listen.local_address().name()? | |
@printf[I32]("Host is: %s\n".cstring(), _host.cstring()) | |
if _host == "::1" then _host = "127.0.0.1" end | |
@printf[I32]("%s external: listening on %s:%s\n".cstring(), | |
_worker_name.cstring(), _host.cstring(), _service.cstring()) | |
else | |
@printf[I32]("%s external: couldn't get local address\n".cstring(), | |
_worker_name.cstring()) | |
listen.close() | |
end | |
fun ref not_listening(listen: TCPListener ref) => | |
@printf[I32]("%s external: couldn't listen\n".cstring(), | |
_worker_name.cstring()) | |
listen.close() | |
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ => | |
_env.out.print("conected") | |
Notify | |
fun ref closed(listen: TCPListener ref) => | |
_env.out.print("closed") | |
this | |
class Notify is TCPConnectionNotify | |
let x: USize | |
new iso create() => | |
x = 1 | |
fun ref connected(conn: TCPConnection ref) => None | |
fun ref connect_failed(conn: TCPConnection ref) => None | |
fun ref closed(conn: TCPConnection ref) => None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment