diff options
author | Russ Cox <rsc@swtch.com> | 2008-08-03 07:42:27 -0700 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2008-08-03 07:42:27 -0700 |
commit | 18824b586835525594cde126fbc90b8281d5af8b (patch) | |
tree | e8b69c05eda4543b6d2f3d30777abe6109b48b7f /src/cmd/smugfs/tcp.c | |
parent | 3d36f4437348227c5bad62587dc12b5fd4a3e95e (diff) | |
download | plan9port-18824b586835525594cde126fbc90b8281d5af8b.tar.gz plan9port-18824b586835525594cde126fbc90b8281d5af8b.tar.bz2 plan9port-18824b586835525594cde126fbc90b8281d5af8b.zip |
smugfs(4): new program
Diffstat (limited to 'src/cmd/smugfs/tcp.c')
-rw-r--r-- | src/cmd/smugfs/tcp.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cmd/smugfs/tcp.c b/src/cmd/smugfs/tcp.c new file mode 100644 index 00000000..a203ece9 --- /dev/null +++ b/src/cmd/smugfs/tcp.c @@ -0,0 +1,50 @@ +#include "a.h" + +struct Pfd +{ + int fd; +}; + +static Pfd* +httpconnect(char *host) +{ + char buf[1024]; + Pfd *pfd; + int fd; + + snprint(buf, sizeof buf, "tcp!%s!http", host); + if((fd = dial(buf, nil, nil, nil)) < 0) + return nil; + pfd = emalloc(sizeof *pfd); + pfd->fd = fd; + return pfd; +} + +static void +httpclose(Pfd *pfd) +{ + if(pfd == nil) + return; + close(pfd->fd); + free(pfd); +} + +static int +httpwrite(Pfd *pfd, void *v, int n) +{ + return writen(pfd->fd, v, n); +} + +static int +httpread(Pfd *pfd, void *v, int n) +{ + return read(pfd->fd, v, n); +} + +Protocol http = { + httpconnect, + httpread, + httpwrite, + httpclose, +}; + |