Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor connection retry #106

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/netlog/netlog-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,24 @@ static int protocol_send(Manager *m, struct iovec *iovec, unsigned n_iovec) {
case SYSLOG_TRANSMISSION_PROTOCOL_DTLS:
r = dtls_datagram_writev(m->dtls, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
dtls_disconnect(m->dtls);
manager_connect(m);
return r;
}
break;
case SYSLOG_TRANSMISSION_PROTOCOL_TLS:
r = tls_stream_writev(m->tls, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
tls_disconnect(m->tls);
manager_connect(m);
return r;
}
break;
case SYSLOG_TRANSMISSION_PROTOCOL_TCP:
default:
r = network_send(m, iovec, n_iovec);
if (r < 0 && r != -EAGAIN) {
manager_close_network_socket(m);
manager_connect(m);
return r;
}
break;
default:
return network_send(m, iovec, n_iovec);
}

return 0;
Expand Down Expand Up @@ -307,28 +305,26 @@ int manager_push_to_network(Manager *m,
switch (m->protocol) {
case SYSLOG_TRANSMISSION_PROTOCOL_DTLS:
if (!m->dtls->connected) {
r = dtls_connect(m->dtls, &m->address);
r = manager_connect(m);
if (r < 0)
return r;
}

break;
case SYSLOG_TRANSMISSION_PROTOCOL_TLS:
if (!m->tls->connected) {
r = tls_connect(m->tls, &m->address);
r = manager_connect(m);
if (r < 0)
return r;
}
break;
case SYSLOG_TRANSMISSION_PROTOCOL_TCP:
default:
if (!m->connected) {
r = manager_open_network_socket(m);
r = manager_connect(m);
if (r < 0)
return r;
}
break;
default:
break;
}

if (m->log_format == SYSLOG_TRANSMISSION_LOG_FORMAT_RFC_5424)
Expand Down Expand Up @@ -489,7 +485,7 @@ int manager_open_network_socket(Manager *m) {
goto fail;

m->connected = true;
return m->socket;
return 0;

fail:
m->socket = safe_close(m->socket);
Expand Down