@@ -30,15 +30,32 @@ function initmatlabls (outFile)
3030end
3131
3232function logConnectionData (outFile )
33- c.matlabPid = feature(" getpid" );
34- c.matlabRelease = [' R' version(' -release' )];
35- c.sessionKey = dduxinternal .getSessionKey();
33+ releaseInfo = matlabRelease ;
3634
37- connectionData = jsonencode(c );
35+ data.pid = feature(" getpid" );
36+ data.release = releaseInfo .Release ;
37+ data.port = matlabls .internal .CommunicationManager .getSecurePort();
38+ data.certFile = matlabls .internal .CommunicationManager .getCertificateLocation();
39+ data.sessionKey = dduxinternal .getSessionKey();
40+
41+ connectionData = jsonencode(data );
3842
3943 disp(strcat(" Printing connection data to file: " , newline , " " , outFile ))
4044
41- f = fopen(outFile , " w" );
42- fprintf(f , " %s\n" , connectionData );
43- fclose(f );
45+ % Write data to a temporary file first, then move to the expected filename to
46+ % avoid a timing issue where partial data may be read from the Node.js layer.
47+ tmpFileName = strcat(outFile , ' -tmp' );
48+
49+ fid = fopen(tmpFileName , " w" );
50+ if (fid == - 1 )
51+ error(" Failed to create temporary connection file." )
52+ end
53+
54+ fprintf(fid , " %s\n" , connectionData );
55+ fclose(fid );
56+
57+ status = movefile(tmpFileName , outFile );
58+ if ~status
59+ error(" Failed to rename connection file." )
60+ end
4461end
0 commit comments