smugfs(4): new program
This commit is contained in:
parent
3d36f44373
commit
18824b5868
17 changed files with 4299 additions and 0 deletions
50
src/cmd/smugfs/tcp.c
Normal file
50
src/cmd/smugfs/tcp.c
Normal file
|
|
@ -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,
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue