Fix deprecation warning

This commit is contained in:
ryuukk 2023-07-29 18:36:00 +02:00 committed by Jan Jurzitza
parent 1c60c5480f
commit 70061aee2e
1 changed files with 29 additions and 26 deletions

View File

@ -260,36 +260,39 @@ AutocompleteResponse getResponse(Socket socket)
*/ */
bool serverIsRunning(bool useTCP, string socketFile, ushort port) bool serverIsRunning(bool useTCP, string socketFile, ushort port)
{ {
scope (failure) try {
return false; AutocompleteRequest request;
AutocompleteRequest request; request.kind = RequestKind.query;
request.kind = RequestKind.query; Socket socket;
Socket socket; scope (exit)
scope (exit)
{
socket.shutdown(SocketShutdown.BOTH);
socket.close();
}
version(Windows) useTCP = true;
if (useTCP)
{
socket = new TcpSocket(AddressFamily.INET);
socket.connect(new InternetAddress("localhost", port));
}
else
{
version(Windows) {} else
{ {
socket = new Socket(AddressFamily.UNIX, SocketType.STREAM); socket.shutdown(SocketShutdown.BOTH);
socket.connect(new UnixAddress(socketFile)); socket.close();
} }
version(Windows) useTCP = true;
if (useTCP)
{
socket = new TcpSocket(AddressFamily.INET);
socket.connect(new InternetAddress("localhost", port));
}
else
{
version(Windows) {} else
{
socket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
socket.connect(new UnixAddress(socketFile));
}
}
socket.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, dur!"seconds"(5));
socket.blocking = true;
if (sendRequest(socket, request))
return getResponse(socket).completionType == "ack";
else
return false;
} }
socket.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, dur!"seconds"(5)); catch (Exception _) {
socket.blocking = true;
if (sendRequest(socket, request))
return getResponse(socket).completionType == "ack";
else
return false; return false;
}
} }
/// Escapes \n, \t and \ in the string. If `single` is true \t won't be escaped. /// Escapes \n, \t and \ in the string. If `single` is true \t won't be escaped.