diff options
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, +}; + |
