sys/src/libventi: implement vtreconn and vtredial functions
This commit is contained in:
parent
8cbe3772c4
commit
63ae9ed53a
4 changed files with 48 additions and 0 deletions
|
@ -334,7 +334,9 @@ struct VtConn
|
|||
};
|
||||
|
||||
VtConn* vtconn(int infd, int outfd);
|
||||
int vtreconn(VtConn*, int, int);
|
||||
VtConn* vtdial(char*);
|
||||
int vtredial(VtConn*, char*);
|
||||
void vtfreeconn(VtConn*);
|
||||
int vtsend(VtConn*, Packet*);
|
||||
Packet* vtrecv(VtConn*);
|
||||
|
|
|
@ -28,9 +28,15 @@ typedef struct VtConn {
|
|||
VtConn* vtconn(int infd, int outfd)
|
||||
.PP
|
||||
.B
|
||||
int vtreconn(VtConn *z, int infd, int outfd)
|
||||
.PP
|
||||
.B
|
||||
VtConn* vtdial(char *addr)
|
||||
.PP
|
||||
.B
|
||||
int vtredial(VtConn *z, char *addr)
|
||||
.PP
|
||||
.B
|
||||
int vtversion(VtConn *z)
|
||||
.PP
|
||||
.B
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue