Closes a shared memory instance.
SharedMemClose(mem-name)
(i)mem-name The name of an active shared memory instance passed to SharedMemOpen.
(i) @True if the instance closed and @False if the instance does not exist.
This function closes a shared memory instance opened using the SharedMemOpen function. All resources associated with a shared memory instance are releases once the last process that called SharedMemOpen for the same named shared memory instance calls SharedMemClose. This function will remove any data written to shared memory by the calling process if no process on the system is waiting to read the named shared memory instance.
;;------------ ;; GetUpTime.WBT ;;------------ IntControl(12,5,0,0,0);Terminate quietly CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive WriteTimeout = 30 ReadTimeout = 60 Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Uptime Client","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') ; Send a request for the server up time. Response = "nothing" Request = "SEND_UPTIME" ReqWait = 1 ;Wait for a response. While ReqWait ReqTimeout = SharedMemWrite(CmdName, Request, WriteTimeout) If !ReqTimeout BoxText(Request:" timed out without response.") Break EndIf BoxText("Waiting for a respones to request: ":Request:Notice) Response = SharedMemRead(DataName, ReadTimeout) If Response != "*NODATA*" || Response != "*TIMEOUT*" Request = "EXIT" SharedMemWrite(CmdName, Request, WriteTimeout) ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Sever up time is ":Response:" exiting") Exit ;;------------ ;; ServerUpTime.WBT ;;------------ IntControl(12,5,0,0,0) ;Terminate quietly WriteTimeout = 30 ReadTimeout = -1 ; Forever. Starttime = GetTickCount64() CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive Request = "GET_UPTIME" Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Get Uptime Example","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') BoxOpen("Uptime Server","Initializing - Awaiting request ":Notice) ReqWait = 1 While ReqWait ; Wait for a request Request = SharedMemRead(CmdName, ReadTimeout) BoxText("Request received: ":Request) If Request == "*NODATA*" || Request == "*TIMEOUT*" Continue ; Not likely to ever get here ElseIf Request == "SEND_UPTIME" Uptime = GetTickCount64() - Starttime Response = Uptime/1440000:' days ':Uptime/60000:' min. ' Response := (Uptime mod 60000)/1000.0:' sec.' bWriteOk = SharedMemWrite(DataName, response, WriteTimeout) If !bWriteOk Then ReqWait = 0 Else BoxText("Sent uptime ":Response) ElseIf Request == "EXIT" ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Exit command received. Server exiting") Exit