… | |
… | |
153 | |
153 | |
154 | You submit a request by calling the relevant C<eio_TYPE> function with the |
154 | You submit a request by calling the relevant C<eio_TYPE> function with the |
155 | required parameters, a callback of type C<int (*eio_cb)(eio_req *req)> |
155 | required parameters, a callback of type C<int (*eio_cb)(eio_req *req)> |
156 | (called C<eio_cb> below) and a freely usable C<void *data> argument. |
156 | (called C<eio_cb> below) and a freely usable C<void *data> argument. |
157 | |
157 | |
158 | The return value will either be 0 |
158 | The return value will either be 0, in case something went really wrong |
|
|
159 | (which can basically only happen on very fatal errors, such as C<malloc> |
|
|
160 | returning 0, which is rather unlikely), or a pointer to the newly-created |
|
|
161 | and submitted C<eio_req *>. |
159 | |
162 | |
160 | The callback will be called with an C<eio_req *> which contains the |
163 | The callback will be called with an C<eio_req *> which contains the |
161 | results of the request. The members you can access inside that structure |
164 | results of the request. The members you can access inside that structure |
162 | vary from request to request, except for: |
165 | vary from request to request, except for: |
163 | |
166 | |
… | |
… | |
226 | custom data value as C<data>. |
229 | custom data value as C<data>. |
227 | |
230 | |
228 | =head3 POSIX API WRAPPERS |
231 | =head3 POSIX API WRAPPERS |
229 | |
232 | |
230 | These requests simply wrap the POSIX call of the same name, with the same |
233 | These requests simply wrap the POSIX call of the same name, with the same |
231 | arguments: |
234 | arguments. If a function is not implemented by the OS and cannot be emulated |
|
|
235 | in some way, then all of these return C<-1> and set C<errorno> to C<ENOSYS>. |
232 | |
236 | |
233 | =over 4 |
237 | =over 4 |
234 | |
238 | |
235 | =item eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) |
239 | =item eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) |
236 | |
240 | |
|
|
241 | =item eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
|
|
242 | |
|
|
243 | =item eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
|
|
244 | |
|
|
245 | =item eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|
|
246 | |
|
|
247 | =item eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|
|
248 | |
|
|
249 | =item eio_rmdir (const char *path, int pri, eio_cb cb, void *data) |
|
|
250 | |
|
|
251 | =item eio_unlink (const char *path, int pri, eio_cb cb, void *data) |
|
|
252 | |
237 | =item eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data) |
253 | =item eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data) |
238 | |
254 | |
239 | =item eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
|
|
240 | |
|
|
241 | =item eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
|
|
242 | |
|
|
243 | =item eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|
|
244 | |
|
|
245 | =item eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|
|
246 | |
|
|
247 | =item eio_rmdir (const char *path, int pri, eio_cb cb, void *data) |
|
|
248 | |
|
|
249 | =item eio_unlink (const char *path, int pri, eio_cb cb, void *data) |
|
|
250 | |
|
|
251 | =item eio_readlink (const char *path, int pri, eio_cb cb, void *data) /* result=ptr2 allocated dynamically */ |
|
|
252 | |
|
|
253 | =item eio_stat (const char *path, int pri, eio_cb cb, void *data) /* stat buffer=ptr2 allocated dynamically */ |
|
|
254 | |
|
|
255 | =item eio_lstat (const char *path, int pri, eio_cb cb, void *data) /* stat buffer=ptr2 allocated dynamically */ |
|
|
256 | |
|
|
257 | =item eio_statvfs (const char *path, int pri, eio_cb cb, void *data) /* stat buffer=ptr2 allocated dynamically */ |
|
|
258 | |
|
|
259 | =item eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) |
255 | =item eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) |
260 | |
256 | |
261 | =item eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
257 | =item eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
262 | |
258 | |
263 | =item eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
259 | =item eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
264 | |
260 | |
265 | =item eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
261 | =item eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
266 | |
262 | |
267 | =item eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
|
|
268 | |
|
|
269 | =item eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data) |
263 | =item eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data) |
270 | |
|
|
271 | =item eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
|
|
272 | |
264 | |
273 | =item eio_close (int fd, int pri, eio_cb cb, void *data) |
265 | =item eio_close (int fd, int pri, eio_cb cb, void *data) |
274 | |
266 | |
275 | =item eio_sync (int pri, eio_cb cb, void *data) |
267 | =item eio_sync (int pri, eio_cb cb, void *data) |
276 | |
268 | |
… | |
… | |
305 | |
297 | |
306 | Not surprisingly, pread and pwrite are not thread-safe on Darwin (OS/X), |
298 | Not surprisingly, pread and pwrite are not thread-safe on Darwin (OS/X), |
307 | so it is advised not to submit multiple requests on the same fd on this |
299 | so it is advised not to submit multiple requests on the same fd on this |
308 | horrible pile of garbage. |
300 | horrible pile of garbage. |
309 | |
301 | |
|
|
302 | =item eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
|
|
303 | |
|
|
304 | Like C<mlockall>, but the flag value constants are called |
|
|
305 | C<EIO_MCL_CURRENT> and C<EIO_MCL_FUTURE>. |
|
|
306 | |
|
|
307 | =item eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
|
|
308 | |
|
|
309 | Just like msync, except that the flag values are called C<EIO_MS_ASYNC>, |
|
|
310 | C<EIO_MS_INVALIDATE> and C<EIO_MS_SYNC>. |
|
|
311 | |
|
|
312 | =item eio_readlink (const char *path, int pri, eio_cb cb, void *data) |
|
|
313 | |
|
|
314 | If successful, the path read by C<readlink(2)> can be accessed via C<< |
|
|
315 | req->ptr2 >> and is I<NOT> null-terminated, with the length specified as |
|
|
316 | C<< req->result >>. |
|
|
317 | |
|
|
318 | if (req->result >= 0) |
|
|
319 | { |
|
|
320 | char *target = strndup ((char *)req->ptr2, req->result); |
|
|
321 | |
|
|
322 | free (target); |
|
|
323 | } |
|
|
324 | |
|
|
325 | =item eio_realpath (const char *path, int pri, eio_cb cb, void *data) |
|
|
326 | |
|
|
327 | Similar to the realpath libc function, but unlike that one, result is |
|
|
328 | C<0> on failure and the length of the returned path in C<ptr2> - this is |
|
|
329 | similar to readlink. |
|
|
330 | |
|
|
331 | =item eio_stat (const char *path, int pri, eio_cb cb, void *data) |
|
|
332 | |
|
|
333 | =item eio_lstat (const char *path, int pri, eio_cb cb, void *data) |
|
|
334 | |
310 | =item eio_fstat (int fd, int pri, eio_cb cb, void *data) |
335 | =item eio_fstat (int fd, int pri, eio_cb cb, void *data) |
311 | |
336 | |
312 | Stats a file - if C<< req->result >> indicates success, then you can |
337 | Stats a file - if C<< req->result >> indicates success, then you can |
313 | access the C<struct stat>-like structure via C<< req->ptr2 >>: |
338 | access the C<struct stat>-like structure via C<< req->ptr2 >>: |
314 | |
339 | |
315 | EIO_STRUCT_STAT *statdata = (EIO_STRUCT_STAT *)req->ptr2; |
340 | EIO_STRUCT_STAT *statdata = (EIO_STRUCT_STAT *)req->ptr2; |
316 | |
341 | |
317 | =item eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) /* stat buffer=ptr2 allocated dynamically */ |
342 | =item eio_statvfs (const char *path, int pri, eio_cb cb, void *data) |
|
|
343 | |
|
|
344 | =item eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) |
318 | |
345 | |
319 | Stats a filesystem - if C<< req->result >> indicates success, then you can |
346 | Stats a filesystem - if C<< req->result >> indicates success, then you can |
320 | access the C<struct statvfs>-like structure via C<< req->ptr2 >>: |
347 | access the C<struct statvfs>-like structure via C<< req->ptr2 >>: |
321 | |
348 | |
322 | EIO_STRUCT_STATVFS *statdata = (EIO_STRUCT_STATVFS *)req->ptr2; |
349 | EIO_STRUCT_STATVFS *statdata = (EIO_STRUCT_STATVFS *)req->ptr2; |
… | |
… | |
338 | (via the C<opendir>, C<readdir> and C<closedir> calls) and returns either |
365 | (via the C<opendir>, C<readdir> and C<closedir> calls) and returns either |
339 | the names or an array of C<struct eio_dirent>, depending on the C<flags> |
366 | the names or an array of C<struct eio_dirent>, depending on the C<flags> |
340 | argument. |
367 | argument. |
341 | |
368 | |
342 | The C<< req->result >> indicates either the number of files found, or |
369 | The C<< req->result >> indicates either the number of files found, or |
343 | C<-1> on error. On success, zero-terminated names can be found as C<< req->ptr2 >>, |
370 | C<-1> on error. On success, null-terminated names can be found as C<< req->ptr2 >>, |
344 | and C<struct eio_dirents>, if requested by C<flags>, can be found via C<< |
371 | and C<struct eio_dirents>, if requested by C<flags>, can be found via C<< |
345 | req->ptr1 >>. |
372 | req->ptr1 >>. |
346 | |
373 | |
347 | Here is an example that prints all the names: |
374 | Here is an example that prints all the names: |
348 | |
375 | |
… | |
… | |
480 | =item eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
507 | =item eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
481 | |
508 | |
482 | Calls C<sync_file_range>. If the syscall is missing, then this is the same |
509 | Calls C<sync_file_range>. If the syscall is missing, then this is the same |
483 | as calling C<fdatasync>. |
510 | as calling C<fdatasync>. |
484 | |
511 | |
|
|
512 | Flags can be any combination of C<EIO_SYNC_FILE_RANGE_WAIT_BEFORE>, |
|
|
513 | C<EIO_SYNC_FILE_RANGE_WRITE> and C<EIO_SYNC_FILE_RANGE_WAIT_AFTER>. |
|
|
514 | |
485 | =back |
515 | =back |
486 | |
516 | |
487 | =head3 LIBEIO-SPECIFIC REQUESTS |
517 | =head3 LIBEIO-SPECIFIC REQUESTS |
488 | |
518 | |
489 | These requests are specific to libeio and do not correspond to any OS call. |
519 | These requests are specific to libeio and do not correspond to any OS call. |
… | |
… | |
547 | |
577 | |
548 | =back |
578 | =back |
549 | |
579 | |
550 | =head3 GROUPING AND LIMITING REQUESTS |
580 | =head3 GROUPING AND LIMITING REQUESTS |
551 | |
581 | |
|
|
582 | There is one more rather special request, C<eio_grp>. It is a very special |
|
|
583 | aio request: Instead of doing something, it is a container for other eio |
|
|
584 | requests. |
|
|
585 | |
|
|
586 | There are two primary use cases for this: a) bundle many requests into a |
|
|
587 | single, composite, request with a definite callback and the ability to |
|
|
588 | cancel the whole request with its subrequests and b) limiting the number |
|
|
589 | of "active" requests. |
|
|
590 | |
|
|
591 | Further below you will find more dicussion of these topics - first follows |
|
|
592 | the reference section detailing the request generator and other methods. |
|
|
593 | |
|
|
594 | =over 4 |
|
|
595 | |
|
|
596 | =item eio_grp (eio_cb cb, void *data) |
|
|
597 | |
|
|
598 | Creates and submits a group request. |
|
|
599 | |
|
|
600 | =back |
|
|
601 | |
|
|
602 | |
|
|
603 | |
552 | #TODO |
604 | #TODO |
553 | |
605 | |
554 | /*****************************************************************************/ |
606 | /*****************************************************************************/ |
555 | /* groups */ |
607 | /* groups */ |
556 | |
608 | |