In a C# class, the following format is used for reading data from a socket asynchronously.
As you can see in the code, it uses AsyncReceive
to read data from a socket. It calls back OnDataReception
when data is received.
In OnDataReception
, received data is processed and again calls ListenForData
if the conversation is not finished yet.
Does this code snippet create any kind of indefinite recursion? (functions or threads)
class ClientConnection{
Socket socket = ...
SocketAsyncEventArgs args = ...
args.Completed += new EventHandler<SocketAsyncEventArgs>(OnDataReception);
...
public void ListenForData(){
...
socket.ReceiveAsync(args);
...
}
public void OnDataReception(Object obj, SocketAsyncEventArgs args){
...
// if conversation is finished, return
// else call ListenForData() again...
}
...
}