ARTICLE AD BOX
I've inherited code that is clearly awful, in syntax, in logic, and in knowledge. I have to assume the code below is also awful because it was the same developer, but I'm not a socket expert so I want to understand why this code was written. Should have been done differently?
The _socket below comes from TcpListener.AcceptSocket(), and then right after that, this function is called. So many things confuse me here.
First, why would Blocking = true be set? Isn't it true that once the socket is accepted, it's no longer blocking anyway?
Ultimately, what I want is to do this: give the socket X seconds to perform the task, at which point it times out. I know the clients have already set their timeout for that, but here on the server, I'm aware that timeouts are useful to prevent socket exhaustion.
Is the code below remotely close to correct for setting this? There's no receive timeout. It's all just very odd code, like the rest of the work I've had to sort through.
public void ConfigureSocket() { int timeout = 500; // in milliseconds _socket.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout ); _socket.Blocking = true; _socket.SendTimeout = 1000; _socket.SendBufferSize = 8192; _socket.LingerState = new LingerOption( true, 10 ); }761k186 gold badges1.4k silver badges1.5k bronze badges
