diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/cec/plan9.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/cec/plan9.c')
-rwxr-xr-x | sys/src/cmd/cec/plan9.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/sys/src/cmd/cec/plan9.c b/sys/src/cmd/cec/plan9.c new file mode 100755 index 000000000..62079e297 --- /dev/null +++ b/sys/src/cmd/cec/plan9.c @@ -0,0 +1,89 @@ +/* Copyright © Coraid, Inc. 2006. All rights reserved. */ +#include <u.h> +#include <libc.h> +#include "cec.h" + +int fd = -1; +int cfd = -1; +int efd = -1; + +int +netopen0(char *e) +{ + char buf[128], ctl[13]; + int n; + + snprint(buf, sizeof buf, "%s/clone", e); + if((efd = open(buf, ORDWR)) == -1) + return -1; + memset(ctl, 0, sizeof ctl); + if(read(efd, ctl, sizeof ctl) < 0) + return -1; + n = atoi(ctl); + snprint(buf, sizeof buf, "connect %d", Etype); + if(write(efd, buf, strlen(buf)) != strlen(buf)) + return -1; + snprint(buf, sizeof buf, "%s/%d/ctl", e, n); + if((cfd = open(buf, ORDWR)) < 0) + return -1; + snprint(buf, sizeof buf, "nonblocking"); + if(write(cfd, buf, strlen(buf)) != strlen(buf)) + return -1; + snprint(buf, sizeof buf, "%s/%d/data", e, n); + fd = open(buf, ORDWR); + return fd; +} + +void +netclose(void) +{ + close(efd); + close(cfd); + close(fd); + efd = -1; + cfd = -1; + fd = -1; +} + +int +netopen(char *e) +{ + int r; + + if((r = netopen0(e)) >= 0) + return r; + perror("netopen"); + netclose(); + return -1; +} + +/* what if len < netlen? */ +int +netget(void *v, int len) +{ + int l; + + l = read(fd, v, len); + if(debug && l > 0){ + fprint(2, "read %d bytes\n", l); + dump((uchar*)v, l); + } + if (l <= 0) + return 0; + return l; +} + +int +netsend(void *v, int len) +{ + uchar *p; + + p = v; + if (debug) { + fprint(2, "sending %d bytes\n", len); + dump(p, len); + } + if (len < 60) + len = 60; /* mintu */ + return write(fd, p, len); +} |