1 #include "ace/OS_NS_sys_sendfile.h"
2 #include "ace/OS_NS_sys_mman.h"
4 #if defined (ACE_WIN32)
5 # include "ace/OS_NS_sys_socket.h"
8 #include "ace/OS_NS_unistd.h"
10 #ifndef ACE_HAS_INLINED_OSCALLS
11 # include "ace/OS_NS_sys_sendfile.inl"
12 #endif /* ACE_HAS_INLINED_OSCALLS */
14 #include "ace/Malloc_Base.h"
15 #include "ace/OS_Memory.h"
16 #include "ace/os_include/os_errno.h"
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 #if defined ACE_HAS_SENDFILE && ACE_HAS_SENDFILE == 0
22 ACE_OS::sendfile_emulation (ACE_HANDLE out_fd
,
27 // @@ Is it possible to inline a call to ::TransmitFile() on
28 // MS Windows instead of emulating here?
30 // @@ We may want set up a signal lease (or oplock) if supported by
31 // the platform so that we don't get a bus error if the mmap()ed
33 void *buf
= ACE_OS::mmap (0, count
, PROT_READ
, MAP_SHARED
, in_fd
, *offset
);
34 const bool use_read
= buf
== MAP_FAILED
&& errno
== ENODEV
;
39 # ifdef ACE_HAS_ALLOC_HOOKS
40 ACE_ALLOCATOR_RETURN (buf
,
41 ACE_Allocator::instance ()->malloc (count
), -1);
43 ACE_NEW_RETURN (buf
, char[count
], -1);
45 prev_pos
= ACE_OS::lseek (in_fd
, 0, SEEK_CUR
);
46 if (ACE_OS::lseek (in_fd
, *offset
, SEEK_SET
) == -1
47 || ACE_OS::read (in_fd
, buf
, count
) == -1)
50 else if (buf
== MAP_FAILED
)
53 #if defined (ACE_WIN32)
55 ACE_OS::send (out_fd
, static_cast<const char *> (buf
), count
);
57 ssize_t
const r
= ACE_OS::write (out_fd
, buf
, count
);
58 #endif /* ACE_WIN32 */
62 ACE_OS::lseek (in_fd
, prev_pos
, SEEK_SET
);
63 # ifdef ACE_HAS_ALLOC_HOOKS
64 ACE_Allocator::instance ()->free (buf
);
66 delete[] static_cast<char *> (buf
);
70 (void) ACE_OS::munmap (buf
, count
);
73 *offset
+= static_cast<off_t
> (r
);
77 #endif /* ACE_HAS_SENDFILE==0 */
79 ACE_END_VERSIONED_NAMESPACE_DECL