Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateOrOpenCore()

static SafeMemoryMappedFileHandle System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpenCore ( string mapName,
HandleInheritability inheritability,
MemoryMappedFileAccess access,
MemoryMappedFileOptions options,
long capacity )
inlinestaticprivate

Definition at line 442 of file MemoryMappedFile.cs.

443 {
444 SafeMemoryMappedFileHandle safeMemoryMappedFileHandle = null;
445 global::Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes = GetSecAttrs(inheritability);
446 int num = 14;
447 int num2 = 0;
448 while (num > 0)
449 {
450 safeMemoryMappedFileHandle = global::Interop.CreateFileMapping(new IntPtr(-1), ref securityAttributes, GetPageAccess(access) | (int)options, capacity, mapName);
451 if (!safeMemoryMappedFileHandle.IsInvalid)
452 {
453 break;
454 }
455 safeMemoryMappedFileHandle.Dispose();
456 int lastPInvokeError = Marshal.GetLastPInvokeError();
457 if (lastPInvokeError != 5)
458 {
459 throw System.IO.Win32Marshal.GetExceptionForWin32Error(lastPInvokeError);
460 }
461 safeMemoryMappedFileHandle = global::Interop.OpenFileMapping(GetFileMapAccess(access), (inheritability & HandleInheritability.Inheritable) != 0, mapName);
462 if (!safeMemoryMappedFileHandle.IsInvalid)
463 {
464 break;
465 }
466 safeMemoryMappedFileHandle.Dispose();
467 int lastPInvokeError2 = Marshal.GetLastPInvokeError();
468 if (lastPInvokeError2 != 2)
469 {
470 throw System.IO.Win32Marshal.GetExceptionForWin32Error(lastPInvokeError2);
471 }
472 num--;
473 if (num2 == 0)
474 {
475 num2 = 10;
476 continue;
477 }
478 Thread.Sleep(num2);
479 num2 *= 2;
480 }
481 if (safeMemoryMappedFileHandle == null || safeMemoryMappedFileHandle.IsInvalid)
482 {
484 }
485 return safeMemoryMappedFileHandle;
486 }
static int GetFileMapAccess(MemoryMappedFileRights rights)
static unsafe global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability)
static int GetPageAccess(MemoryMappedFileAccess access)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string InvalidOperation_CantCreateFileMapping
Definition SR.cs:66
Definition SR.cs:7
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658

References System.capacity, System.Runtime.InteropServices.SafeHandle.Dispose(), System.IO.Win32Marshal.GetExceptionForWin32Error(), System.IO.MemoryMappedFiles.MemoryMappedFile.GetFileMapAccess(), System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), System.IO.MemoryMappedFiles.MemoryMappedFile.GetPageAccess(), System.IO.MemoryMappedFiles.MemoryMappedFile.GetSecAttrs(), System.SR.InvalidOperation_CantCreateFileMapping, Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle.IsInvalid, System.options, and System.Threading.Thread.Sleep().

Referenced by System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen().