Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file sendfile.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129exceptionDarwin_specific_unix_errorof(Unix.error*int)let()=Callback.register_exception"sendfile_exn_unix_error"(Darwin_specific_unix_error(Unix.E2BIG,0));Printexc.register_printer(function|Darwin_specific_unix_error(unix_error,len)->letmsg=(* Copied from
https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/unix_unix.ml *)matchunix_errorwith|E2BIG->"E2BIG"|EACCES->"EACCES"|EAGAIN->"EAGAIN"|EBADF->"EBADF"|EBUSY->"EBUSY"|ECHILD->"ECHILD"|EDEADLK->"EDEADLK"|EDOM->"EDOM"|EEXIST->"EEXIST"|EFAULT->"EFAULT"|EFBIG->"EFBIG"|EINTR->"EINTR"|EINVAL->"EINVAL"|EIO->"EIO"|EISDIR->"EISDIR"|EMFILE->"EMFILE"|EMLINK->"EMLINK"|ENAMETOOLONG->"ENAMETOOLONG"|ENFILE->"ENFILE"|ENODEV->"ENODEV"|ENOENT->"ENOENT"|ENOEXEC->"ENOEXEC"|ENOLCK->"ENOLCK"|ENOMEM->"ENOMEM"|ENOSPC->"ENOSPC"|ENOSYS->"ENOSYS"|ENOTDIR->"ENOTDIR"|ENOTEMPTY->"ENOTEMPTY"|ENOTTY->"ENOTTY"|ENXIO->"ENXIO"|EPERM->"EPERM"|EPIPE->"EPIPE"|ERANGE->"ERANGE"|EROFS->"EROFS"|ESPIPE->"ESPIPE"|ESRCH->"ESRCH"|EXDEV->"EXDEV"|EWOULDBLOCK->"EWOULDBLOCK"|EINPROGRESS->"EINPROGRESS"|EALREADY->"EALREADY"|ENOTSOCK->"ENOTSOCK"|EDESTADDRREQ->"EDESTADDRREQ"|EMSGSIZE->"EMSGSIZE"|EPROTOTYPE->"EPROTOTYPE"|ENOPROTOOPT->"ENOPROTOOPT"|EPROTONOSUPPORT->"EPROTONOSUPPORT"|ESOCKTNOSUPPORT->"ESOCKTNOSUPPORT"|EOPNOTSUPP->"EOPNOTSUPP"|EPFNOSUPPORT->"EPFNOSUPPORT"|EAFNOSUPPORT->"EAFNOSUPPORT"|EADDRINUSE->"EADDRINUSE"|EADDRNOTAVAIL->"EADDRNOTAVAIL"|ENETDOWN->"ENETDOWN"|ENETUNREACH->"ENETUNREACH"|ENETRESET->"ENETRESET"|ECONNABORTED->"ECONNABORTED"|ECONNRESET->"ECONNRESET"|ENOBUFS->"ENOBUFS"|EISCONN->"EISCONN"|ENOTCONN->"ENOTCONN"|ESHUTDOWN->"ESHUTDOWN"|ETOOMANYREFS->"ETOOMANYREFS"|ETIMEDOUT->"ETIMEDOUT"|ECONNREFUSED->"ECONNREFUSED"|EHOSTDOWN->"EHOSTDOWN"|EHOSTUNREACH->"EHOSTUNREACH"|ELOOP->"ELOOP"|EOVERFLOW->"EOVERFLOW"|EUNKNOWNERRx->Printf.sprintf"EUNKNOWNERR %d"xinSome(Format.asprintf"Sendfile(Unix_error): %s; remaining len: %d"msglen)|_->None)externalsendfile:src:Unix.file_descr->dst:Unix.file_descr->off:int->len:int->int="ocaml_sendfile_sendfile_stub"letsendfile_once_exn?(off=0)~len~srcdst=trysendfile~src~dst~off~lenwith|Darwin_specific_unix_error(unix_err,_)->raise(Unix.Unix_error(unix_err,"sendfile",""))letsendfile_once?(off=0)~len~srcdst=tryOk(sendfile_once_exn~src~off~lendst)with|Unix.Unix_error(unix_err,_,_msg)->Errorunix_errletsendfile_exn?(off=0)?len~srcdst=letrecsendfile_exn~off~len~srcdst=matchsendfile~src~off~len~dstwith|cwhenc=len->len|c->sendfile_exn~src~off:(off+c)~len:(len-c)dst|exceptionUnix.Unix_error((EINTR|EAGAIN),_,_)->sendfile_exn~src~off~lendst|exceptionDarwin_specific_unix_error((EINTR|EAGAIN),sent)->(* Darwin systems signal the number of bytes partially sent on EINTR /
EAGAIN. *)sendfile_exn~src~off:(off+sent)~len:(len-sent)dst|exceptionDarwin_specific_unix_error(unix_err,_)->raise(Unix.Unix_error(unix_err,"sendfile",""))inletlen=matchlenwithSomelen->len|None->(Unix.fstatsrc).st_size-offinlet_sent=sendfile_exn~off~len~srcdstin(* If we're here, we sent the whole file correctly, so we return the total
length sent. *)lenletsendfile?off?len~srcdst=tryOk(sendfile_exn~src?off?lendst)with|Unix.Unix_error(unix_err,_,_msg)->Errorunix_err