summaryrefslogtreecommitdiff
path: root/appl/cmd/styxchat.b
diff options
context:
space:
mode:
Diffstat (limited to 'appl/cmd/styxchat.b')
-rw-r--r--appl/cmd/styxchat.b37
1 files changed, 13 insertions, 24 deletions
diff --git a/appl/cmd/styxchat.b b/appl/cmd/styxchat.b
index f66b49fe..20d0d968 100644
--- a/appl/cmd/styxchat.b
+++ b/appl/cmd/styxchat.b
@@ -20,6 +20,9 @@ include "bufio.m";
bufio: Bufio;
Iobuf: import bufio;
+include "dial.m";
+ dial: Dial;
+
include "arg.m";
Styxchat: module
@@ -39,6 +42,7 @@ init(nil: ref Draw->Context, args: list of string)
styx = load Styx Styx->PATH;
str = load String String->PATH;
bufio = load Bufio Bufio->PATH;
+ dial = load Dial Dial->PATH;
styx->init();
client := 1;
@@ -74,21 +78,21 @@ init(nil: ref Draw->Context, args: list of string)
stdin = sys->fildes(0);
dest := hd args;
if(addr){
- dest = netmkaddr(dest, "net", "styx");
+ dest = dial->netmkaddr(dest, "net", "styx");
if (client){
- (rc, c) := sys->dial(dest, nil);
- if(rc < 0)
+ c := dial->dial(dest, nil);
+ if(c == nil)
err(sys->sprint("can't dial %s: %r", dest));
fd = c.dfd;
}else{
- (rlc, lc) := sys->announce(dest);
- if (rlc < 0)
+ lc := dial->announce(dest);
+ if(lc == nil)
err(sys->sprint("can't announce %s: %r", dest));
- (rc, c) := sys->listen(lc);
- if (rc < 0)
+ c := dial->listen(lc);
+ if(c == nil)
err(sys->sprint("can't listen on %s: %r", dest));
- fd = sys->open(c.dir + "/data", Sys->ORDWR);
- if (fd == nil)
+ fd = dial->accept(c);
+ if(fd == nil)
err(sys->sprint("can't open %s/data: %r", c.dir));
}
}else{
@@ -107,21 +111,6 @@ init(nil: ref Draw->Context, args: list of string)
}
}
-netmkaddr(addr, net, svc: string): string
-{
- if(net == nil)
- net = "net";
- (n, nil) := sys->tokenize(addr, "!");
- if(n <= 1){
- if(svc== nil)
- return sys->sprint("%s!%s", net, addr);
- return sys->sprint("%s!%s!%s", net, addr, svc);
- }
- if(svc == nil || n > 2)
- return addr;
- return sys->sprint("%s!%s", addr, svc);
-}
-
quit(e: int)
{
fd := sys->open("/prog/"+string sys->pctl(0, nil)+"/ctl", Sys->OWRITE);