Reputation: 307
I just want to make sure I understand the SocketAsyncEventArgs reusability feature. As I understand, the SocketAsyncEventArgs can be reused for one connection and different operations. So I would be able to use the same SocketAsyncEventArgs for Connect/Send/Receive (Client) or Accept/Send/Receive (Server)? Or do I still need to use new SocketAsyncEventArgs for the different operations?
And I also understand that the SocketAsyncEventArgs are primarily designed for high performance on server side. So the proper use would be to have a SocketAsyncEventArgs pool on a server to hold one SocketAsyncEventArgs for every connection. And to reuse the SocketAsyncEventArgs for the different operations on the connections. On client side you could just use one SocketAsyncEventArgs.
Do I understand this right? Unfortunately I didn't find a clear statement on this in the documentation.
Upvotes: 0
Views: 217
Reputation: 307
Answering my own question: SocketAsyncEventArgs replace the IAsyncResult which are required for the Begin.../End... Methods. Therefore for a server you still have to have a Socket for listening. But you have for every connected client now a SocketAsyncEventArg instead of a Socket. The SocketAsyncEventArgs are reusable in sense of being usable for all operations with the same connected client. The improvement is that you don't have the IAsyncResult for every operation operation on a connected client. This decreases pressure on the GC.
Upvotes: 0