changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: sys/src/libventi: implement vtreconn and vtredial functions

changeset 7364: 4947baafd1f3
parent 7362: b2e82d7a1e5b
child 7365: e40a49d58913
author: David du Colombier <0intro@gmail.com>
date: Fri, 06 Sep 2019 11:54:44 -0700
files: sys/include/venti.h sys/man/2/venti-conn sys/src/libventi/conn.c sys/src/libventi/dial.c
description: sys/src/libventi: implement vtreconn and vtredial functions
     1.1--- a/sys/include/venti.h
     1.2+++ b/sys/include/venti.h
     1.3@@ -334,7 +334,9 @@ struct VtConn
     1.4 };
     1.5 
     1.6 VtConn*	vtconn(int infd, int outfd);
     1.7+int	vtreconn(VtConn*, int, int);
     1.8 VtConn*	vtdial(char*);
     1.9+int	vtredial(VtConn*, char*);
    1.10 void	vtfreeconn(VtConn*);
    1.11 int	vtsend(VtConn*, Packet*);
    1.12 Packet*	vtrecv(VtConn*);
     2.1--- a/sys/man/2/venti-conn
     2.2+++ b/sys/man/2/venti-conn
     2.3@@ -28,9 +28,15 @@ typedef struct VtConn {
     2.4 VtConn*	vtconn(int infd, int outfd)
     2.5 .PP
     2.6 .B
     2.7+int	vtreconn(VtConn *z, int infd, int outfd)
     2.8+.PP
     2.9+.B
    2.10 VtConn*	vtdial(char *addr)
    2.11 .PP
    2.12 .B
    2.13+int	vtredial(VtConn *z, char *addr)
    2.14+.PP
    2.15+.B
    2.16 int	vtversion(VtConn *z)
    2.17 .PP
    2.18 .B
     3.1--- a/sys/src/libventi/conn.c
     3.2+++ b/sys/src/libventi/conn.c
     3.3@@ -27,6 +27,28 @@ vtconn(int infd, int outfd)
     3.4 	return z;
     3.5 }
     3.6 
     3.7+int
     3.8+vtreconn(VtConn *z, int infd, int outfd)
     3.9+{
    3.10+	NetConnInfo *nci;
    3.11+
    3.12+	z->state = VtStateAlloc;
    3.13+	if(z->infd >= 0)
    3.14+		close(z->infd);
    3.15+	z->infd = infd;
    3.16+	if(z->outfd >= 0)
    3.17+		close(z->outfd);
    3.18+	z->outfd = outfd;
    3.19+	nci = getnetconninfo(nil, infd);
    3.20+	if(nci == nil)
    3.21+		snprint(z->addr, sizeof z->addr, "/dev/fd/%d", infd);
    3.22+	else{
    3.23+		strecpy(z->addr, z->addr+sizeof z->addr, nci->raddr);
    3.24+		freenetconninfo(nci);
    3.25+	}
    3.26+	return 0;
    3.27+}
    3.28+
    3.29 void
    3.30 vtfreeconn(VtConn *z)
    3.31 {
     4.1--- a/sys/src/libventi/dial.c
     4.2+++ b/sys/src/libventi/dial.c
     4.3@@ -23,3 +23,21 @@ vtdial(char *addr)
     4.4 		strecpy(z->addr, z->addr+sizeof z->addr, na);
     4.5 	return z;
     4.6 }
     4.7+
     4.8+int
     4.9+vtredial(VtConn *z, char *addr)
    4.10+{
    4.11+	char *na;
    4.12+	int fd;
    4.13+
    4.14+	if(addr == nil)
    4.15+		addr = getenv("venti");
    4.16+	if(addr == nil)
    4.17+		addr = "$venti";
    4.18+
    4.19+	na = netmkaddr(addr, "tcp", "venti");
    4.20+	if((fd = dial(na, nil, nil, nil)) < 0)
    4.21+		return fd;
    4.22+
    4.23+	return vtreconn(z, fd, fd);
    4.24+}