gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10816: port to win32, replace mmap(


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10816: port to win32, replace mmap() with win32 calls.
Date: Mon, 20 Apr 2009 16:36:23 -0600
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10816
committer: address@hidden
branch nick: trunk
timestamp: Mon 2009-04-20 16:36:23 -0600
message:
  port to win32, replace mmap() with win32 calls.
modified:
  libnet/diskstream.cpp
=== modified file 'libnet/diskstream.cpp'
--- a/libnet/diskstream.cpp     2009-02-25 22:33:03 +0000
+++ b/libnet/diskstream.cpp     2009-04-20 22:36:23 +0000
@@ -27,9 +27,13 @@
 #include <iostream>
 #include <string>
 #include <cerrno>
+#ifndef _WIN32
 #include <sys/mman.h>
+#else
+#include <windows.h>
+#endif
+
 #include "GnashSystemIOHeaders.h"
-
 #include "network.h"
 #include "buffer.h"
 #include "amf.h"
@@ -63,6 +67,10 @@
 ///    This is the maximum number of pages that we load into memory from a 
file.
 const size_t MAX_PAGES = 2560;
 
+#ifndef MAP_FAILED
+#define MAP_FAILED 0
+#endif
+
 DiskStream::DiskStream()
     : _state(DiskStream::NO_STATE),
       _filefd(0),
@@ -79,8 +87,15 @@
     _pagesize = sysconf(_SC_PAGESIZE);
     _max_memload = _pagesize * MAX_PAGES;    
 #else
+#if _WIN32
+    // The default page size for Win32 is 4k
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    _pagesize = si.dwPageSize;
+#else
 #error "Need to define the memory page size without sysconf()!"
 #endif
+#endif
 
 #ifdef USE_STATS_CACHE
     clock_gettime (CLOCK_REALTIME, &_last_access);
@@ -104,8 +119,14 @@
     _pagesize = sysconf(_SC_PAGESIZE);
     _max_memload = _pagesize * MAX_PAGES;    
 #else
+#ifdef _WIN32
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    _pagesize = si.dwPageSize;
+#else
 #error "Need to define the memory page size without sysconf()!"
 #endif
+#endif
 
     _filespec = str;
 #ifdef USE_STATS_CACHE
@@ -130,8 +151,14 @@
     _pagesize = sysconf(_SC_PAGESIZE);
     _max_memload = _pagesize * MAX_PAGES;    
 #else
+#ifdef _WIN32
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    _pagesize = si.dwPageSize;
+#else
 #error "Need to define the memory page size without sysconf()!"
 #endif
+#endif
 
     _dataptr = new boost::uint8_t[size];
     // Note that this is a copy operation, which may effect performance. We do 
this for now
@@ -163,8 +190,14 @@
     _pagesize = sysconf(_SC_PAGESIZE);
     _max_memload = _pagesize * MAX_PAGES;    
 #else
+#ifdef _WIN32
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    _pagesize = si.dwPageSize;
+#else
 #error "Need to define the memory page size without sysconf()!"
 #endif
+#endif
 
     _dataptr = new boost::uint8_t[buf.size()];
     // Note that this is a copy operation, which may effect performance. We do 
this for now
@@ -196,8 +229,14 @@
     _pagesize = sysconf(_SC_PAGESIZE);
     _max_memload = _pagesize * MAX_PAGES;    
 #else
+#ifdef _WIN32
+    SYSTEM_INFO si;
+    GetSystemInfo(&si);
+    _pagesize = si.dwPageSize;
+#else
 #error "Need to define the memory page size without sysconf()!"
 #endif
+#endif
 
     _netfd = netfd;
     _filespec = str;
@@ -233,12 +272,16 @@
     _filesize = 0;
     _offset = 0;
     
+#ifdef _WIN32
+    UnmapViewOfFile(_dataptr);
+#else
     if ((_dataptr != MAP_FAILED) && (_dataptr != 0)) {
        munmap(_dataptr, _pagesize);
 //     delete[] _dataptr;
-       _dataptr = 0;
     }
-     
+#endif
+    
+    _dataptr = 0; 
     _filefd = 0;
     _state = CLOSED;
 //    _filespec.clear();
@@ -314,7 +357,11 @@
        /// to mmap() a new one. If we're still in the current mapped
        /// page, then just return the existing data pointer.
        if (dataptr != 0) {
+#ifdef _WIN32
+           UnmapViewOfFile(_dataptr);
+#else
            munmap(_dataptr, _pagesize);
+#endif
        }
 #if 0
        // See if the page has already been mapped in;
@@ -328,8 +375,19 @@
 //         size = _filesize;
 //     }
 
-       dataptr = static_cast<unsigned char *>(mmap(0, loadsize,
-                                                    PROT_READ, MAP_SHARED, 
_filefd, page));
+#ifdef _WIN32
+       HANDLE handle = CreateFileMapping((HANDLE)_get_osfhandle(_filefd), NULL,
+                                         PAGE_WRITECOPY, 0, 0, NULL);
+       if (handle != NULL) {
+           dataptr = static_cast<boost::uint8_t *>(MapViewOfFile(handle, 
FILE_MAP_COPY, 0, offset, page));
+           CloseHandle(handle);
+
+       }
+#else
+       dataptr = static_cast<boost::uint8_t *>(mmap(0, loadsize,
+                                                    PROT_READ, MAP_SHARED,
+                                                    _filefd, page));
+#endif
     } else {
        log_error (_("Couldn't load file %s"), _filespec);
        return 0;
@@ -545,7 +603,12 @@
     
     log_debug("Done...");
           
+#ifdef _WIN32
+    UnmapViewOfFile(_dataptr);
+#else
     munmap(_dataptr, _filesize);
+#endif
+    
     _seekptr = 0;
 
     return true;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]