mirror of https://gitlab.com/basile.b/dexed.git
dcd, windows, wait propertly for the socket to be ready
+ wait properly for termination
This commit is contained in:
parent
6ee4cb1927
commit
f7cb97831c
|
@ -38,6 +38,7 @@ type
|
||||||
procedure waitClient; inline;
|
procedure waitClient; inline;
|
||||||
procedure updateServerlistening;
|
procedure updateServerlistening;
|
||||||
procedure writeSourceToInput; inline;
|
procedure writeSourceToInput; inline;
|
||||||
|
function checkDcdSocket: boolean;
|
||||||
//
|
//
|
||||||
procedure projNew(aProject: ICECommonProject);
|
procedure projNew(aProject: ICECommonProject);
|
||||||
procedure projChanged(aProject: ICECommonProject);
|
procedure projChanged(aProject: ICECommonProject);
|
||||||
|
@ -77,33 +78,6 @@ const
|
||||||
optsname = 'dcdoptions.txt';
|
optsname = 'dcdoptions.txt';
|
||||||
|
|
||||||
|
|
||||||
function checkDcdSocket: boolean;
|
|
||||||
var
|
|
||||||
str: string;
|
|
||||||
begin
|
|
||||||
sleep(100);
|
|
||||||
// nix/osx: the file might exists from a previous session that crashed
|
|
||||||
// however the 100 ms might be enough for DCD to initializes
|
|
||||||
{$IFDEF LINUX}
|
|
||||||
str := sysutils.GetEnvironmentVariable('XDG_RUNTIME_DIR');
|
|
||||||
if (str + DirectorySeparator + 'dcd.socket').fileExists then
|
|
||||||
exit(true);
|
|
||||||
str := sysutils.GetEnvironmentVariable('UID');
|
|
||||||
if ('/tmp/dcd-' + str + '.socket').fileExists then
|
|
||||||
exit(true);
|
|
||||||
{$ENDIF}
|
|
||||||
{$IFDEF DARWIN}
|
|
||||||
str := sysutils.GetEnvironmentVariable('UID');
|
|
||||||
if ('/var/tmp/dcd-' + str + '.socket').fileExists then
|
|
||||||
exit(true);
|
|
||||||
{$ENDIF}
|
|
||||||
//windows: just hope that the 100 ms were enough
|
|
||||||
{$IFDEF WINDOWS}
|
|
||||||
exit(true);
|
|
||||||
{$ENDIF}
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{$REGION Standard Comp/Obj------------------------------------------------------}
|
{$REGION Standard Comp/Obj------------------------------------------------------}
|
||||||
constructor TCEDcdWrapper.create(aOwner: TComponent);
|
constructor TCEDcdWrapper.create(aOwner: TComponent);
|
||||||
var
|
var
|
||||||
|
@ -160,15 +134,26 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCEDcdWrapper.destroy;
|
destructor TCEDcdWrapper.destroy;
|
||||||
|
var
|
||||||
|
i: integer = 0;
|
||||||
begin
|
begin
|
||||||
saveToFile(getCoeditDocPath + optsname);
|
saveToFile(getCoeditDocPath + optsname);
|
||||||
EntitiesConnector.removeObserver(self);
|
EntitiesConnector.removeObserver(self);
|
||||||
fImportCache.Free;
|
fImportCache.Free;
|
||||||
if fTempLines.isNotNil then
|
if fTempLines.isNotNil then
|
||||||
fTempLines.Free;
|
fTempLines.Free;
|
||||||
if fServer.isNotNil then begin
|
if fServer.isNotNil then
|
||||||
|
begin
|
||||||
if not fServerWasRunning then
|
if not fServerWasRunning then
|
||||||
|
begin
|
||||||
killServer;
|
killServer;
|
||||||
|
while true do
|
||||||
|
begin
|
||||||
|
if (not checkDcdSocket) or (i = 10) then
|
||||||
|
break;
|
||||||
|
i +=1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
fServer.Free;
|
fServer.Free;
|
||||||
end;
|
end;
|
||||||
fClient.Free;
|
fClient.Free;
|
||||||
|
@ -264,6 +249,64 @@ begin
|
||||||
fClient.Terminate(0);
|
fClient.Terminate(0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCEDcdWrapper.checkDcdSocket: boolean;
|
||||||
|
var
|
||||||
|
str: string;
|
||||||
|
{$IFDEF WINDOWS}
|
||||||
|
prt: word = 9166;
|
||||||
|
prc: TProcess;
|
||||||
|
lst: TStringList;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
sleep(100);
|
||||||
|
// nix/osx: the file might exists from a previous session that crashed
|
||||||
|
// however the 100 ms might be enough for DCD to initializes
|
||||||
|
{$IFDEF LINUX}
|
||||||
|
str := sysutils.GetEnvironmentVariable('XDG_RUNTIME_DIR');
|
||||||
|
if (str + DirectorySeparator + 'dcd.socket').fileExists then
|
||||||
|
exit(true);
|
||||||
|
str := sysutils.GetEnvironmentVariable('UID');
|
||||||
|
if ('/tmp/dcd-' + str + '.socket').fileExists then
|
||||||
|
exit(true);
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
str := sysutils.GetEnvironmentVariable('UID');
|
||||||
|
if ('/var/tmp/dcd-' + str + '.socket').fileExists then
|
||||||
|
exit(true);
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF WINDOWS}
|
||||||
|
result := false;
|
||||||
|
if port <> 0 then prt := port;
|
||||||
|
prc := TProcess.Create(nil);
|
||||||
|
try
|
||||||
|
prc.Options:= [poUsePipes, poNoConsole];
|
||||||
|
prc.Executable := 'netstat';
|
||||||
|
prc.Parameters.Add('-o');
|
||||||
|
prc.Parameters.Add('-a');
|
||||||
|
prc.Parameters.Add('-n');
|
||||||
|
prc.Execute;
|
||||||
|
lst := TStringList.Create;
|
||||||
|
try
|
||||||
|
processOutputToStrings(prc,lst);
|
||||||
|
for str in lst do
|
||||||
|
if AnsiContainsText(str, '127.0.0.1:' + intToStr(prt))
|
||||||
|
and AnsiContainsText(str, 'TCP')
|
||||||
|
and AnsiContainsText(str, 'LISTENING') then
|
||||||
|
begin
|
||||||
|
result := true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
lst.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
prc.Free;
|
||||||
|
end;
|
||||||
|
exit(result);
|
||||||
|
{$ENDIF}
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCEDcdWrapper.killServer;
|
procedure TCEDcdWrapper.killServer;
|
||||||
begin
|
begin
|
||||||
if not fAvailable then exit;
|
if not fAvailable then exit;
|
||||||
|
|
Loading…
Reference in New Issue