Skip to content

Commit

Permalink
Merge pull request #106 from ssahani/misc
Browse files Browse the repository at this point in the history
Refactor connection retry
  • Loading branch information
ssahani authored May 22, 2024
2 parents 9cd12b5 + 8c6bff9 commit 85cacff
Showing 1 changed file with 9 additions and 13 deletions.
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

0 comments on commit 85cacff

Please sign in to comment.