Blob
1 #include "a.h"3 struct Pfd4 {5 int fd;6 };8 static Pfd*9 httpconnect(char *host)10 {11 char buf[1024];12 Pfd *pfd;13 int fd;15 snprint(buf, sizeof buf, "tcp!%s!http", host);16 if((fd = dial(buf, nil, nil, nil)) < 0)17 return nil;18 pfd = emalloc(sizeof *pfd);19 pfd->fd = fd;20 return pfd;21 }23 static void24 httpclose(Pfd *pfd)25 {26 if(pfd == nil)27 return;28 close(pfd->fd);29 free(pfd);30 }32 static int33 httpwrite(Pfd *pfd, void *v, int n)34 {35 return writen(pfd->fd, v, n);36 }38 static int39 httpread(Pfd *pfd, void *v, int n)40 {41 return read(pfd->fd, v, n);42 }44 Protocol http = {45 httpconnect,46 httpread,47 httpwrite,48 httpclose,49 };