Commit 361f91cd authored by Jozef Kralik's avatar Jozef Kralik

Merge branch 'fixHandlingTcpClosedConnection' into plgd.dev

parents 2c78643b d8fe723b
Pipeline #1268 passed with stage
in 3 minutes and 27 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");
......
......@@ -1894,6 +1894,8 @@ read_application_data_tcp(oc_tls_peer_t *peer)
peer->processed_recv_message->length == total_length) {
OC_DBG("oc_tls_tcp: Decrypted incoming message %d",
(int)(total_length));
peer->processed_recv_message->encrypted = 0;
memcpy(peer->processed_recv_message->endpoint.di.id, peer->uuid.id, 16);
if (oc_process_post(&coap_engine, oc_events[INBOUND_RI_EVENT],
peer->processed_recv_message) ==
OC_PROCESS_ERR_FULL) {
......
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