aboutsummaryrefslogtreecommitdiff
path: root/src/libventi
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2011-11-08 09:02:31 -0500
committerRuss Cox <rsc@swtch.com>2011-11-08 09:02:31 -0500
commit4544da52005bf0af3bb05a73f4e02ce35117aae0 (patch)
treea9e3f60b9c118a578ac6d9e017979cd938a665bc /src/libventi
parent36c242dd868672ae9c6705622ef1e7dbb84dbbac (diff)
downloadplan9port-4544da52005bf0af3bb05a73f4e02ce35117aae0.tar.gz
plan9port-4544da52005bf0af3bb05a73f4e02ce35117aae0.tar.bz2
plan9port-4544da52005bf0af3bb05a73f4e02ce35117aae0.zip
libventi: add functions reconn and redial for use with fossil
R=rsc CC=plan9port.codebot http://codereview.appspot.com/5325046
Diffstat (limited to 'src/libventi')
-rw-r--r--src/libventi/conn.c22
-rw-r--r--src/libventi/dial.c18
2 files changed, 40 insertions, 0 deletions
diff --git a/src/libventi/conn.c b/src/libventi/conn.c
index e488c6db..2a8f67b9 100644
--- a/src/libventi/conn.c
+++ b/src/libventi/conn.c
@@ -27,6 +27,28 @@ vtconn(int infd, int outfd)
return z;
}
+int
+vtreconn(VtConn *z, int infd, int outfd)
+{
+ NetConnInfo *nci;
+
+ z->state = VtStateAlloc;
+ if(z->infd >= 0)
+ close(z->infd);
+ z->infd = infd;
+ if(z->outfd >= 0)
+ close(z->outfd);
+ z->outfd = outfd;
+ nci = getnetconninfo(nil, infd);
+ if(nci == nil)
+ snprint(z->addr, sizeof z->addr, "/dev/fd/%d", infd);
+ else{
+ strecpy(z->addr, z->addr+sizeof z->addr, nci->raddr);
+ freenetconninfo(nci);
+ }
+ return 0;
+}
+
void
vtfreeconn(VtConn *z)
{
diff --git a/src/libventi/dial.c b/src/libventi/dial.c
index 060b93f6..00482473 100644
--- a/src/libventi/dial.c
+++ b/src/libventi/dial.c
@@ -23,3 +23,21 @@ vtdial(char *addr)
strecpy(z->addr, z->addr+sizeof z->addr, na);
return z;
}
+
+int
+vtredial(VtConn *z, char *addr)
+{
+ char *na;
+ int fd;
+
+ if(addr == nil)
+ addr = getenv("venti");
+ if(addr == nil)
+ addr = "$venti";
+
+ na = netmkaddr(addr, "tcp", "venti");
+ if((fd = dial(na, nil, nil, nil)) < 0)
+ return fd;
+
+ return vtreconn(z, fd, fd);
+}