OS_NS_sys_sendfile.cpp

Go to the documentation of this file.
00001 // OS_NS_sys_sendfile.cpp,v 1.4 2006/06/19 09:59:49 jwillemsen Exp
00002 
00003 #include "ace/OS_NS_sys_sendfile.h"
00004 #include "ace/OS_NS_sys_mman.h"
00005 
00006 #if defined (ACE_WIN32) || defined (HPUX)
00007 # include "ace/OS_NS_sys_socket.h"
00008 #else
00009 # include "ace/OS_NS_unistd.h"
00010 #endif  /* ACE_WIN32 || HPUX */
00011 
00012 #ifndef ACE_HAS_INLINED_OSCALLS
00013 # include "ace/OS_NS_sys_sendfile.inl"
00014 #endif  /* ACE_HAS_INLINED_OS_CALLS */
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 #ifndef ACE_HAS_SENDFILE
00019 ssize_t
00020 ACE_OS::sendfile_emulation (ACE_HANDLE out_fd,
00021                             ACE_HANDLE in_fd,
00022                             off_t * offset,
00023                             size_t count)
00024 {
00025   // @@ Is it possible to inline a call to ::TransmitFile() on
00026   //    MS Windows instead of emulating here?
00027 
00028   // @@ We may want set up a signal lease (or oplock) if supported by
00029   //    the platform so that we don't get a bus error if the mmap()ed
00030   //    file is truncated.
00031   void * const buf =
00032     ACE_OS::mmap (0, count, PROT_READ, MAP_SHARED, in_fd, *offset);
00033 
00034   if (buf == MAP_FAILED)
00035     return -1;
00036 
00037 #if defined (ACE_WIN32) || defined (HPUX)
00038   ssize_t const r =
00039     ACE_OS::send (out_fd, static_cast<const char *> (buf), count);
00040 #else
00041   ssize_t const r = ACE_OS::write (out_fd, buf, count);
00042 #endif /* ACE_WIN32 */
00043 
00044   (void) ACE_OS::munmap (buf, count);
00045 
00046   if (r > 0)
00047     *offset += static_cast<off_t> (r);
00048 
00049   return r;
00050 }
00051 #endif  /* !ACE_HAS_SENDFILE */
00052 
00053 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:58 2006 for ACE by doxygen 1.3.6