Restore build on FreeBSD.
[getmangos.git] / dep / ACE_wrappers / ace / OS_NS_sys_sendfile.cpp
blob8f48c7a20303581901313e9d638eedfa2b0a608d
1 // $Id: OS_NS_sys_sendfile.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/OS_NS_sys_sendfile.h"
4 #include "ace/OS_NS_sys_mman.h"
6 #if defined (ACE_WIN32) || defined (HPUX)
7 # include "ace/OS_NS_sys_socket.h"
8 #else
9 # include "ace/OS_NS_unistd.h"
10 #endif /* ACE_WIN32 || HPUX */
12 #ifndef ACE_HAS_INLINED_OSCALLS
13 # include "ace/OS_NS_sys_sendfile.inl"
14 #endif /* ACE_HAS_INLINED_OSCALLS */
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 #ifndef ACE_HAS_SENDFILE
19 ssize_t
20 ACE_OS::sendfile_emulation (ACE_HANDLE out_fd,
21 ACE_HANDLE in_fd,
22 off_t * offset,
23 size_t count)
25 // @@ Is it possible to inline a call to ::TransmitFile() on
26 // MS Windows instead of emulating here?
28 // @@ We may want set up a signal lease (or oplock) if supported by
29 // the platform so that we don't get a bus error if the mmap()ed
30 // file is truncated.
31 void * const buf =
32 ACE_OS::mmap (0, count, PROT_READ, MAP_SHARED, in_fd, *offset);
34 if (buf == MAP_FAILED)
35 return -1;
37 #if defined (ACE_WIN32) || defined (HPUX)
38 ssize_t const r =
39 ACE_OS::send (out_fd, static_cast<const char *> (buf), count);
40 #else
41 ssize_t const r = ACE_OS::write (out_fd, buf, count);
42 #endif /* ACE_WIN32 */
44 (void) ACE_OS::munmap (buf, count);
46 if (r > 0)
47 *offset += static_cast<off_t> (r);
49 return r;
51 #endif /* !ACE_HAS_SENDFILE */
53 ACE_END_VERSIONED_NAMESPACE_DECL