aboutsummaryrefslogtreecommitdiffstats
path: root/logd/src/logd/conn.cpp
blob: 2ad9093011ab08c364b1c0842bdccc38f6691866 (plain) (blame)
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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "conn.h"
#include <vespa/vespalib/net/socket_address.h>

#include <vespa/log/log.h>
LOG_SETUP("");

namespace logdemon {

static int retryBeforeWarningCount = 20;

int makeconn(const char *logSrvHost, int logPort)
{
    auto handle = vespalib::SocketAddress::select_remote(logPort, logSrvHost).connect();
    if (!handle) {
        const char *msgfmt = "Cannot connect to logserver on %s:%d: %s";
        if (retryBeforeWarningCount > 0) {
            --retryBeforeWarningCount;
            LOG(debug, msgfmt, logSrvHost, logPort, strerror(errno));
        } else {
            LOG(warning, msgfmt, logSrvHost, logPort, strerror(errno));
        }
        return -1;
    }
    LOG(debug, "Made new connection to port %d. Connected to daemon.", logPort);
    return handle.release();
}

} // namespace