summaryrefslogtreecommitdiff
path: root/appl/cmd/listen.b
diff options
context:
space:
mode:
authorCharles Forsyth <charles.forsyth@gmail.com>2015-04-29 17:44:33 +0100
committerCharles Forsyth <charles.forsyth@gmail.com>2015-04-29 17:44:33 +0100
commitfbc1184c08d18d5ac0f8763a058e015e95353341 (patch)
treef045cdfaaf13c35295d34cb0c2ffd7f4cf2ef30d /appl/cmd/listen.b
parent83eae27259078c96c074211a51bf38c774490544 (diff)
switch to Dial module
Diffstat (limited to 'appl/cmd/listen.b')
-rw-r--r--appl/cmd/listen.b29
1 files changed, 17 insertions, 12 deletions
diff --git a/appl/cmd/listen.b b/appl/cmd/listen.b
index 25869223..61c5ecf9 100644
--- a/appl/cmd/listen.b
+++ b/appl/cmd/listen.b
@@ -7,6 +7,8 @@ include "keyring.m";
keyring: Keyring;
include "security.m";
auth: Auth;
+include "dial.m";
+ dial: Dial;
include "sh.m";
sh: Sh;
Context: import sh;
@@ -31,6 +33,9 @@ init(drawctxt: ref Draw->Context, argv: list of string)
auth = load Auth Auth->PATH;
if (auth == nil)
badmodule(Auth->PATH);
+ dial = load Dial Dial->PATH;
+ if (dial == nil)
+ badmodule(Dial->PATH);
sh = load Sh Sh->PATH;
if (sh == nil)
badmodule(Sh->PATH);
@@ -120,8 +125,8 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
sys->pctl(Sys->FORKFD, nil);
ctxt := Context.new(drawctxt);
- (ok, acon) := sys->announce(addr);
- if (ok == -1) {
+ acon := dial->announce(addr);
+ if (acon == nil) {
sys->fprint(stderr(), "listen: failed to announce on '%s': %r\n", addr);
sync <-= "cannot announce";
exit;
@@ -146,12 +151,12 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
}
sync <-= nil;
- listench := chan of (int, Sys->Connection);
- authch := chan of (string, Sys->Connection);
+ listench := chan of (int, ref Sys->Connection);
+ authch := chan of (string, ref Sys->Connection);
spawn listener(listench, acon, addr);
for (;;) {
user := "";
- ccon: Sys->Connection;
+ ccon: ref Sys->Connection;
alt {
(lok, c) := <-listench =>
if (lok == -1){
@@ -182,11 +187,11 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
}
}
-listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: string)
+listener(listench: chan of (int, ref Sys->Connection), c: ref Sys->Connection, addr: string)
{
for (;;) {
- (ok, nc) := sys->listen(c);
- if (ok == -1) {
+ nc := dial->listen(c);
+ if (nc == nil) {
sys->fprint(stderr(), "listen: listen error on '%s': %r\n", addr);
listench <-= (-1, nc);
exit;
@@ -194,19 +199,19 @@ listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: str
if (verbose)
sys->fprint(stderr(), "listen: got connection on %s from %s",
addr, readfile(nc.dir + "/remote"));
- nc.dfd = sys->open(nc.dir + "/data", Sys->ORDWR);
+ nc.dfd = dial->accept(nc);
if (nc.dfd == nil)
sys->fprint(stderr(), "listen: cannot open %s: %r\n", nc.dir + "/data");
else{
if(nc.cfd != nil)
sys->fprint(nc.cfd, "keepalive");
- listench <-= (ok, nc);
+ listench <-= (0, nc);
}
}
}
-authenticator(authch: chan of (string, Sys->Connection),
- c: Sys->Connection, algs: list of string, addr: string)
+authenticator(authch: chan of (string, ref Sys->Connection),
+ c: ref Sys->Connection, algs: list of string, addr: string)
{
err: string;
(c.dfd, err) = auth->server(algs, serverkey, c.dfd, 0);