Commit 41d5527c authored by Jozef Kralik's avatar Jozef Kralik

tcp: don't reconnect to closed connection created by accept

parent f684e2d2
Pipeline #1266 failed with stage
in 3 minutes and 5 seconds
......@@ -54,7 +54,8 @@ enum transport_flags {
IPV6 = 1 << 3,
TCP = 1 << 4,
GATT = 1 << 5,
MULTICAST = 1 << 6
MULTICAST = 1 << 6,
ACCEPTED = 1 << 7
};
typedef struct oc_endpoint_t
......
......@@ -334,7 +334,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
message->endpoint.device = dev->device;
if (FD_ISSET(dev->tcp.server_sock, fds)) {
message->endpoint.flags = IPV6 | TCP;
message->endpoint.flags = IPV6 | TCP ACCEPTED;
if (accept_new_session(dev, dev->tcp.server_sock, fds, &message->endpoint) <
0) {
OC_ERR("accept new session fail");
......@@ -343,7 +343,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
ret_with_code(ADAPTER_STATUS_ACCEPT);
#ifdef OC_SECURITY
} else if (FD_ISSET(dev->tcp.secure_sock, fds)) {
message->endpoint.flags = IPV6 | SECURED | TCP;
message->endpoint.flags = IPV6 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure_sock, fds, &message->endpoint) <
0) {
OC_ERR("accept new session fail");
......@@ -353,7 +353,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
#endif /* OC_SECURITY */
#ifdef OC_IPV4
} else if (FD_ISSET(dev->tcp.server4_sock, fds)) {
message->endpoint.flags = IPV4 | TCP;
message->endpoint.flags = IPV4 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server4_sock, fds,
&message->endpoint) < 0) {
OC_ERR("accept new session fail");
......@@ -362,7 +362,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
ret_with_code(ADAPTER_STATUS_ACCEPT);
#ifdef OC_SECURITY
} else if (FD_ISSET(dev->tcp.secure4_sock, fds)) {
message->endpoint.flags = IPV4 | SECURED | TCP;
message->endpoint.flags = IPV4 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure4_sock, fds,
&message->endpoint) < 0) {
OC_ERR("accept new session fail");
......@@ -600,6 +600,10 @@ oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message,
size_t bytes_sent = 0;
if (send_sock < 0) {
if (message->endpoint.flags & ACCEPTED) {
OC_ERR("connection was closed");
goto oc_tcp_send_buffer_done;
}
if ((send_sock = initiate_new_session(dev, &message->endpoint, receiver)) <
0) {
OC_ERR("could not initiate new TCP session");
......
......@@ -348,7 +348,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
if (FD_ISSET(dev->tcp.server_sock, fds))
{
message->endpoint.flags = IPV6 | TCP;
message->endpoint.flags = IPV6 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server_sock, fds, &message->endpoint) <
0)
{
......@@ -360,7 +360,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
}
else if (FD_ISSET(dev->tcp.secure_sock, fds))
{
message->endpoint.flags = IPV6 | SECURED | TCP;
message->endpoint.flags = IPV6 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure_sock, fds, &message->endpoint) <
0)
{
......@@ -373,7 +373,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
}
else if (FD_ISSET(dev->tcp.server4_sock, fds))
{
message->endpoint.flags = IPV4 | TCP;
message->endpoint.flags = IPV4 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server4_sock, fds,
&message->endpoint) < 0)
{
......@@ -385,7 +385,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
}
else if (FD_ISSET(dev->tcp.secure4_sock, fds))
{
message->endpoint.flags = IPV4 | SECURED | TCP;
message->endpoint.flags = IPV4 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure4_sock, fds,
&message->endpoint) < 0)
{
......@@ -656,6 +656,10 @@ int oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message,
size_t bytes_sent = 0;
if (send_sock < 0)
{
if (message->endpoint.flags & ACCEPTED) {
OC_ERR("connection was closed");
goto oc_tcp_send_buffer_done;
}
if ((send_sock = initiate_new_session(dev, &message->endpoint, receiver)) <
0)
{
......
......@@ -320,7 +320,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
message->endpoint.device = dev->device;
if (FD_ISSET(dev->tcp.server_sock, fds)) {
message->endpoint.flags = IPV6 | TCP;
message->endpoint.flags = IPV6 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server_sock, fds, &message->endpoint) <
0) {
OC_ERR("accept new session fail");
......@@ -329,7 +329,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
ret_with_code(ADAPTER_STATUS_ACCEPT);
#ifdef OC_SECURITY
} else if (FD_ISSET(dev->tcp.secure_sock, fds)) {
message->endpoint.flags = IPV6 | SECURED | TCP;
message->endpoint.flags = IPV6 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure_sock, fds, &message->endpoint) <
0) {
OC_ERR("accept new session fail");
......@@ -339,7 +339,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
#endif /* OC_SECURITY */
#ifdef OC_IPV4
} else if (FD_ISSET(dev->tcp.server4_sock, fds)) {
message->endpoint.flags = IPV4 | TCP;
message->endpoint.flags = IPV4 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server4_sock, fds,
&message->endpoint) < 0) {
OC_ERR("accept new session fail");
......@@ -348,7 +348,7 @@ oc_tcp_receive_message(ip_context_t *dev, fd_set *fds, oc_message_t *message)
ret_with_code(ADAPTER_STATUS_ACCEPT);
#ifdef OC_SECURITY
} else if (FD_ISSET(dev->tcp.secure4_sock, fds)) {
message->endpoint.flags = IPV4 | SECURED | TCP;
message->endpoint.flags = IPV4 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure4_sock, fds,
&message->endpoint) < 0) {
OC_ERR("accept new session fail");
......@@ -586,6 +586,10 @@ oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message,
size_t bytes_sent = 0;
if (send_sock < 0) {
if (message->endpoint.flags & ACCEPTED) {
OC_ERR("connection was closed");
goto oc_tcp_send_buffer_done;
}
if ((send_sock = initiate_new_session(dev, &message->endpoint, receiver)) <
0) {
OC_ERR("could not initiate new TCP session");
......
......@@ -486,6 +486,10 @@ oc_tcp_send_buffer(ip_context_t *dev, oc_message_t *message,
int bytes_sent = 0;
if (send_sock == INVALID_SOCKET) {
if (message->endpoint.flags & ACCEPTED) {
OC_ERR("connection was closed");
goto oc_tcp_send_buffer_done;
}
if ((send_sock = initiate_new_session_locked(dev, &message->endpoint,
receiver)) == INVALID_SOCKET) {
OC_ERR("could not initiate new TCP session");
......@@ -620,7 +624,7 @@ accept_socket(SOCKET s, void *ctx)
if (!(network_events.lNetworkEvents & (FD_ACCEPT | FD_CLOSE))) {
return;
}
endpoint.flags = IPV6 | TCP;
endpoint.flags = IPV6 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server_sock, &endpoint) ==
SOCKET_ERROR) {
OC_ERR("accept new tcp session fail");
......@@ -636,7 +640,7 @@ accept_socket(SOCKET s, void *ctx)
if (!(network_events.lNetworkEvents & (FD_ACCEPT | FD_CLOSE))) {
return;
}
endpoint.flags = IPV6 | SECURED | TCP;
endpoint.flags = IPV6 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure_sock, &endpoint) ==
SOCKET_ERROR) {
OC_ERR("accept new tcp secure session fail");
......@@ -653,7 +657,7 @@ accept_socket(SOCKET s, void *ctx)
if (!(network_events.lNetworkEvents & (FD_ACCEPT | FD_CLOSE))) {
return;
}
endpoint.flags = IPV4 | TCP;
endpoint.flags = IPV4 | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.server4_sock, &endpoint) ==
SOCKET_ERROR) {
OC_ERR("accept new tcp4 session fail");
......@@ -669,7 +673,7 @@ accept_socket(SOCKET s, void *ctx)
if (!(network_events.lNetworkEvents & (FD_ACCEPT | FD_CLOSE))) {
return;
}
endpoint.flags = IPV4 | SECURED | TCP;
endpoint.flags = IPV4 | SECURED | TCP | ACCEPTED;
if (accept_new_session(dev, dev->tcp.secure4_sock, &endpoint) ==
SOCKET_ERROR) {
OC_ERR("accept new tcp4 secure session fail");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment