|
5 | 5 | use "std/internal/poll" |
6 | 6 | use "std/io" |
7 | 7 | use "std/sys" |
| 8 | +use "std/time" |
8 | 9 | use "std/unsafe" |
9 | 10 |
|
10 | 11 | // The name of the operating system's “null device.” |
@@ -213,6 +214,36 @@ impl File { |
213 | 214 | ret self.fd.ShouldAsync() |
214 | 215 | } |
215 | 216 |
|
| 217 | + // Sets or updates a deadline for the future read operations. |
| 218 | + // If the deadline is given as 0, the deadline is cleared. |
| 219 | + // The deadline is evaluated against an absolute point in time. |
| 220 | + // In practice, the given deadline is equivalent to `time::Now().Add(deadline)`. |
| 221 | + // It does not apply per operation, but remains valid until this absolute time. |
| 222 | + // Any operation initiated after this deadline has passed will fail. |
| 223 | + // |
| 224 | + // If file does not supports async I/O, throws error. |
| 225 | + fn SetReadDeadline(mut *self, deadline: time::Duration)! { |
| 226 | + if !self.ShouldAsync() { |
| 227 | + throw poll::ErrNoDeadline |
| 228 | + } |
| 229 | + self.fd.SetReadDeadline(deadline) |
| 230 | + } |
| 231 | + |
| 232 | + // Sets or updates a deadline for the future write operations. |
| 233 | + // If the deadline is given as 0, the deadline is cleared. |
| 234 | + // The deadline is evaluated against an absolute point in time. |
| 235 | + // In practice, the given deadline is equivalent to `time::Now().Add(deadline)`. |
| 236 | + // It does not apply per operation, but remains valid until this absolute time. |
| 237 | + // Any operation initiated after this deadline has passed will fail. |
| 238 | + // |
| 239 | + // If file does not supports async I/O, throws error. |
| 240 | + fn SetWriteDeadline(mut *self, deadline: time::Duration)! { |
| 241 | + if !self.ShouldAsync() { |
| 242 | + throw poll::ErrNoDeadline |
| 243 | + } |
| 244 | + self.fd.SetWriteDeadline(deadline) |
| 245 | + } |
| 246 | + |
216 | 247 | // Writes bytes to handle and returns written byte count. |
217 | 248 | // The number of bytes written can never exceed the length of the buf. |
218 | 249 | async fn Write(mut *self, buf: []byte)!: (n: int) { |
|
0 commit comments