I am seeing weird file mapping behaviour on Windows: When desktop client starts, it sets an ID (not a UUID) to issue a CreateSharedMemory(id, 131072) call to a newly created FileMappingMBS instance.
No problem on macOS. Under Windows I get an error 87: Wrong parameter. 131072 is a multiple of 4096, and the id is “CCExactFS”. What could be wrong about them?
Console client who receives that id to open the shared Memory answers with an error 2: system cannot find the file.
Absolutely weird thing is I used to Nil the FileMappings if they errored but forgot to include checks for the file mapping itself, which works(!!) although being nil. Just that an overflow error can occur because the memory limit seems to be at minimum 4k.
How can that even work? FileMapping object is not recreated.
And, more important: What can be wrong about my parameters?
Thank you both, but neither of that works.
Here’s the code I use in desktop to establish connection. Desktop client may live through several console helper restarts, that’s why I check for existing connection first. But does not change if I don’t.
The FileMapping object exists afterwards anyway, is writable but with a memory limit of -4.
mUUIDString = value
#If TargetDesktop
If FileMapping = Nil Then
FileMapping = New FileMappingMBS
log "FileMapping id " + value + ", size " + mSharedMemorySize.ToString
var ok As Boolean = FileMapping.OpenSharedMemory(value)
If Not ok Then
ok = FileMapping.CreateSharedMemory(value, SharedMemorySize)
If Not ok Then
HandleException MakeException(-112, "Could not create file mapping"), CurrentMethodName
MakeFileMappingError CurrentMethodName
Else
#If TargetMacOS
FileMapping.DeleteSharedMemory = True
#EndIf
log "FileMapping established"
End If
Else
log "reusing FileMapping"
End If
End If
Call write kcaptureuuid, EncodeBase64URLMBS(value)
(and here the client receives the id and tries to open connection too)
Ok. I could fix a bit now. Part of the problem was my desktop control setting its sharedmemsize property to 0 in IDE constructor although this was not an IDE behaviour enabled property. Other was a problem in my helper communication being stuck for some reason.
There is anyhow still a weirdness:
on macOS, helper reports SharedMemorySize to be the size I set it to (65536 currently). On Windows, both console and desktop report -1. So I am uncertain if the buffer size was set correctly. Documentation says this property exists on all systems, and FileMapping object is not nil, writable and has no error when using it. What does -1 mean then?
Addition: And yes, transmission size on Windows is limited to 4k. Which is probably what -1 stands for.
The same is valid for your Shared Memory Server example. SharedMemorySize is at -1 when you run it on windows.
EDIT: I tried to use a file-based approach for Windows now, using the constructor that takes a folder item and write permission.
When using Nil as Folderitem, supposedly making the file being part of the internal cache, the constructor threw an exception saying folder item is nil.
With a file created in the temp folder, constructor works, opening works, but afterwards I see in debugger file is nil and SharedMemorySize is -1 still. Which goes along with trying to send bigger strings.