Michal Glowacki wrote:I am wondering, how to swap to check-alive-thread when awaiting an input from server socket. So, my app is continously awaiting data from socket, but another thread should make a check fx each second if the waiting time not exceeded x seconds.
There is no need for swaping the thread reading the data. All it needs to do is have a state variable (volatile) that tells whether it has received any data or not.
As soon as you start reading start a
Timer (simplest approach) which checks for the state variable every "x" minutes [Every X minutes if you want to keep the socket reader alive forever and it should get something every x seconds]. If the state variable says that the data is not received the interrupt the reader thread or inform the admin, as your application demands.