00001 
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  
00011 
00012 #ifndef ACE_HAS_INLINED_OSCALLS
00013 # include "ace/OS_NS_sys_sendfile.inl"
00014 #endif  
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   
00026   
00027 
00028   
00029   
00030   
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 
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  
00052 
00053 ACE_END_VERSIONED_NAMESPACE_DECL