mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Delete socket file at exit
This commit is contained in:
parent
830b79d6b1
commit
3f4feeb830
4 changed files with 33 additions and 7 deletions
|
|
@ -200,7 +200,8 @@ end;
|
|||
|
||||
destructor TServerListnerThread.Destroy;
|
||||
begin
|
||||
FreeAndNil(FSocketObject);
|
||||
WriteLn('TServerListnerThread.Destroy');
|
||||
FSocketObject.StopAccepting(True);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
|
@ -210,10 +211,11 @@ begin
|
|||
FSocketObject:= TUnixServer.Create('/tmp/' + FOwner.Name);
|
||||
try
|
||||
FSocketObject.Bind;
|
||||
FReadyEvent.SetEvent;
|
||||
FSocketObject.OnConnect:= @DoConnect;
|
||||
FSocketObject.StartAccepting;
|
||||
finally
|
||||
FSocketObject.Free;
|
||||
FreeAndNil(FSocketObject);
|
||||
end;
|
||||
except
|
||||
on e : Exception do
|
||||
|
|
|
|||
|
|
@ -269,6 +269,8 @@ begin
|
|||
|
||||
DCDebug('Start server ', AName);
|
||||
|
||||
FReadyEvent.SetEvent;
|
||||
|
||||
// Wait client connection
|
||||
if not (ConnectNamedPipe(hPipe, nil) or (GetLastError() = ERROR_PIPE_CONNECTED)) then
|
||||
CloseHandle(hPipe)
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ procedure CreateWorkerProxy();
|
|||
procedure CreateMasterProxy(const AName: String);
|
||||
|
||||
var
|
||||
MasterService: TMasterService;
|
||||
WorkerService: TWorkerService;
|
||||
MasterService: TMasterService = nil;
|
||||
WorkerService: TWorkerService = nil;
|
||||
|
||||
implementation
|
||||
|
||||
|
|
@ -479,12 +479,24 @@ begin
|
|||
CreateWorkerProxy;
|
||||
end;
|
||||
|
||||
procedure Finalize;
|
||||
begin
|
||||
if WorkerProcess > 0 then begin
|
||||
WorkerProxy.Terminate;
|
||||
end;
|
||||
if Assigned(MasterService) then
|
||||
begin
|
||||
DoneCriticalSection(Mutex);
|
||||
MasterService.Free;
|
||||
end;
|
||||
WorkerService.Free;
|
||||
end;
|
||||
|
||||
initialization
|
||||
Initialize;
|
||||
|
||||
finalization
|
||||
if WorkerProcess > 0 then WorkerProxy.Terminate;
|
||||
DoneCriticalSection(Mutex);
|
||||
Finalize;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ unit uService;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
Classes, SysUtils, SyncObjs;
|
||||
|
||||
type
|
||||
|
||||
|
|
@ -61,9 +61,11 @@ type
|
|||
|
||||
TServerThread = class(TThread)
|
||||
protected
|
||||
FReadyEvent: TEvent;
|
||||
FOwner : TBaseService;
|
||||
public
|
||||
constructor Create(AOwner : TBaseService);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
|
@ -76,9 +78,16 @@ uses
|
|||
constructor TServerThread.Create(AOwner: TBaseService);
|
||||
begin
|
||||
FOwner := AOwner;
|
||||
FReadyEvent:= TSimpleEvent.Create;
|
||||
inherited Create(False);
|
||||
end;
|
||||
|
||||
destructor TServerThread.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
FReadyEvent.Free;
|
||||
end;
|
||||
|
||||
{ TBaseService }
|
||||
|
||||
constructor TBaseService.Create(const AName: String);
|
||||
|
|
@ -99,6 +108,7 @@ end;
|
|||
procedure TBaseService.Start;
|
||||
begin
|
||||
FServerThread:= TServerListnerThread.Create(Self);
|
||||
TServerThread(FServerThread).FReadyEvent.WaitFor(30000);
|
||||
end;
|
||||
|
||||
{ TClientThread }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue