rsc | 1544f90 | 2004-12-25 21:56:33 +0000 | [diff] [blame] | 1 | #include <u.h> |
| 2 | #include <unistd.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <libc.h> |
| 5 | #include <fcall.h> |
| 6 | #include <thread.h> |
| 7 | #include "ioproc.h" |
| 8 | |
| 9 | static long |
| 10 | _ioclose(va_list *arg) |
| 11 | { |
| 12 | int fd; |
| 13 | |
| 14 | fd = va_arg(*arg, int); |
| 15 | return close(fd); |
| 16 | } |
| 17 | int |
| 18 | ioclose(Ioproc *io, int fd) |
| 19 | { |
| 20 | return iocall(io, _ioclose, fd); |
| 21 | } |
| 22 | |
| 23 | static long |
| 24 | _iodial(va_list *arg) |
| 25 | { |
| 26 | char *addr, *local, *dir; |
| 27 | int *cdfp, fd; |
| 28 | |
| 29 | addr = va_arg(*arg, char*); |
| 30 | local = va_arg(*arg, char*); |
| 31 | dir = va_arg(*arg, char*); |
| 32 | cdfp = va_arg(*arg, int*); |
| 33 | |
| 34 | fd = dial(addr, local, dir, cdfp); |
| 35 | return fd; |
| 36 | } |
| 37 | int |
| 38 | iodial(Ioproc *io, char *addr, char *local, char *dir, int *cdfp) |
| 39 | { |
| 40 | return iocall(io, _iodial, addr, local, dir, cdfp); |
| 41 | } |
| 42 | |
| 43 | static long |
| 44 | _ioopen(va_list *arg) |
| 45 | { |
| 46 | char *path; |
| 47 | int mode; |
| 48 | |
| 49 | path = va_arg(*arg, char*); |
| 50 | mode = va_arg(*arg, int); |
| 51 | return open(path, mode); |
| 52 | } |
| 53 | int |
| 54 | ioopen(Ioproc *io, char *path, int mode) |
| 55 | { |
| 56 | return iocall(io, _ioopen, path, mode); |
| 57 | } |
| 58 | |
| 59 | static long |
| 60 | _ioread(va_list *arg) |
| 61 | { |
| 62 | int fd; |
| 63 | void *a; |
| 64 | long n; |
| 65 | |
| 66 | fd = va_arg(*arg, int); |
| 67 | a = va_arg(*arg, void*); |
| 68 | n = va_arg(*arg, long); |
| 69 | return read(fd, a, n); |
| 70 | } |
| 71 | long |
| 72 | ioread(Ioproc *io, int fd, void *a, long n) |
| 73 | { |
| 74 | return iocall(io, _ioread, fd, a, n); |
| 75 | } |
| 76 | |
| 77 | static long |
| 78 | _ioreadn(va_list *arg) |
| 79 | { |
| 80 | int fd; |
| 81 | void *a; |
| 82 | long n; |
| 83 | |
| 84 | fd = va_arg(*arg, int); |
| 85 | a = va_arg(*arg, void*); |
| 86 | n = va_arg(*arg, long); |
| 87 | n = readn(fd, a, n); |
| 88 | return n; |
| 89 | } |
| 90 | long |
| 91 | ioreadn(Ioproc *io, int fd, void *a, long n) |
| 92 | { |
| 93 | return iocall(io, _ioreadn, fd, a, n); |
| 94 | } |
| 95 | |
| 96 | static long |
| 97 | _iosleep(va_list *arg) |
| 98 | { |
| 99 | long n; |
| 100 | |
| 101 | n = va_arg(*arg, long); |
| 102 | return sleep(n); |
| 103 | } |
| 104 | int |
| 105 | iosleep(Ioproc *io, long n) |
| 106 | { |
| 107 | return iocall(io, _iosleep, n); |
| 108 | } |
| 109 | |
| 110 | static long |
| 111 | _iowrite(va_list *arg) |
| 112 | { |
| 113 | int fd; |
| 114 | void *a; |
| 115 | long n, nn; |
| 116 | |
| 117 | fd = va_arg(*arg, int); |
| 118 | a = va_arg(*arg, void*); |
| 119 | n = va_arg(*arg, long); |
| 120 | nn = write(fd, a, n); |
| 121 | return nn; |
| 122 | } |
| 123 | long |
| 124 | iowrite(Ioproc *io, int fd, void *a, long n) |
| 125 | { |
rsc | af89fc1 | 2005-01-06 23:07:19 +0000 | [diff] [blame] | 126 | n = iocall(io, _iowrite, fd, a, n); |
| 127 | return n; |
rsc | 1544f90 | 2004-12-25 21:56:33 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static long |
| 131 | _iosendfd(va_list *arg) |
| 132 | { |
| 133 | int n, fd, fd2; |
| 134 | |
| 135 | fd = va_arg(*arg, int); |
| 136 | fd2 = va_arg(*arg, int); |
| 137 | n = sendfd(fd, fd2); |
| 138 | return n; |
| 139 | } |
| 140 | int |
| 141 | iosendfd(Ioproc *io, int fd, int fd2) |
| 142 | { |
| 143 | return iocall(io, _iosendfd, fd, fd2); |
| 144 | } |
| 145 | |
| 146 | static long |
| 147 | _iorecvfd(va_list *arg) |
| 148 | { |
| 149 | int n, fd; |
| 150 | |
| 151 | fd = va_arg(*arg, int); |
| 152 | n = recvfd(fd); |
| 153 | return n; |
| 154 | } |
| 155 | int |
| 156 | iorecvfd(Ioproc *io, int fd) |
| 157 | { |
| 158 | return iocall(io, _iorecvfd, fd); |
| 159 | } |
| 160 | |
| 161 | static long |
| 162 | _ioread9pmsg(va_list *arg) |
| 163 | { |
| 164 | int fd; |
| 165 | void *a; |
| 166 | int n; |
| 167 | int r; |
| 168 | |
| 169 | fd = va_arg(*arg, int); |
| 170 | a = va_arg(*arg, void*); |
| 171 | n = va_arg(*arg, int); |
| 172 | r = read9pmsg(fd, a, n); |
| 173 | return n; |
| 174 | } |
| 175 | int |
| 176 | ioread9pmsg(Ioproc *io, int fd, void *a, int n) |
| 177 | { |
| 178 | return iocall(io, _ioread9pmsg, fd, a, n); |
| 179 | } |