Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/***********************************************************************************************************************************
Server Ping Command
***********************************************************************************************************************************/
#include <build.h>
 
#include "command/server/ping.h"
#include "common/debug.h"
#include "common/io/socket/client.h"
#include "common/io/tls/client.h"
#include "config/config.h"
#include "protocol/client.h"
#include "protocol/helper.h"
 
FN_EXTERN void
cmdServerPing(void)
{
    FUNCTION_LOG_VOID(logLevelDebug);
 
    MEM_CONTEXT_TEMP_BEGIN()
    {
        // Check for user-specified host
        const String *host = cfgOptionStr(cfgOptTlsServerAddress);
        const StringList *const commandParam = cfgCommandParam();
 
        if (strLstSize(commandParam) == 1)
            host = strLstGet(commandParam, 0);
        else if (strLstSize(commandParam) > 1)
            THROW(ParamInvalidError, "extra parameters found");
 
        // Connect to server without any verification
        const TimeMSec timeout = cfgOptionUInt64(cfgOptIoTimeout);
 
        IoClient *const tlsClient = tlsClientNewP(
            sckClientNew(host, cfgOptionUInt(cfgOptTlsServerPort), timeout, timeout), host, timeout, timeout, false);
        IoSession *const tlsSession = ioClientOpen(tlsClient);
 
        // Send ping
        ProtocolClient *const protocolClient = protocolClientNew(
            strNewFmt(PROTOCOL_SERVICE_REMOTE " socket protocol on '%s'", strZ(host)), PROTOCOL_SERVICE_REMOTE_STR,
            ioSessionIoReadP(tlsSession), ioSessionIoWrite(tlsSession));
        protocolClientNoExit(protocolClient);
        protocolClientNoOp(protocolClient);
        protocolClientFree(protocolClient);
    }
    MEM_CONTEXT_TEMP_END();
 
    FUNCTION_LOG_RETURN_VOID();
}