Skip to content
yfakariya edited this page May 2, 2012 · 1 revision

Socket Shutdown

Socket shutdown is initiated from client or server on following reason:

  • Client application will be exit, so the application initiates graceful shutdown. This causes graceful shutdown.
  • Client application was exit without initiating shutdown or crushed, so the connection is closed. This causes rude shutdown.
  • Server application will be exit, so the application initiates graceful shutdown. This causes graceful shutdown.
  • Server application was exit without initiating shutdown or crushded, so the connection is closed. This causes rude shutdown.

If socket shutdown is initiated rudely, the error (like "Connection Reset" error) is occurred in opposite side. If socket shutdown is initiated gracefully, following events will be occurred.

Client Initiated Shutdown

Client behavior is following:

  1. ClientTransport.BeginShutdown is called, then the transport go to 'is in shutdown' state. Subsequent Send invocation will be fail.
  2. ClientTransport initiates sending shutdown. For TCP/IP, underlying socket API sends FIN packet.
  3. ClientTransport cancels pending sending operations.
  4. ClientTransport invokes all asynchronous callbacks with cancellation error.
  5. ClientTransport wait for the server also shutdown sending with processing pending response.
  6. ClientTransport receives server shutdown packet, initiates receiving shutdown.
  7. ClientTransport raises ShutdownCompleted event.

Server behavior is following:

  1. ServerTransport receives client shutdown notification.
  2. ServerTransport raises ClientShutdown event.
  3. ServerTransport initiates receiving shutdown.
  4. ServerTransport processes remaining pending request as possible, and discards requests/notifications which are not able to dispatch.
  5. ServerTransport responds all responses to the client.
  6. When the count of pending request reach to zero, ServerTransport initiates sending shutdown. For TCP/IP, underlying socket API sends FIN packet.
  7. ServerTransport raises ShutdownCompleted event.

Server Initiated Shutdown

Server behavior is following:

  1. ServerTransport.BeginShutdown is called.
  2. ServerTransport initiates receiving shutdown.
  3. ServerTransport processes remaining pending request as possible, and discards requests/notifications which are not able to dispatch.
  4. ServerTransport responds all responses to the client.
  5. When the count of pending request reach to zero, ServerTransport initiates sending shutdown. For TCP/IP, underlying socket API sends FIN

Client behavior is following:

  1. ClientTransport receives server shutdown notification.
  2. ClientTransport raises ServerShutdown event.
  3. ClientTransport initiates receiving shutdown.
  4. ClientTransport cancels pending sending operations.
  5. ClientTransport invokes all asynchronous callbacks with cancellation error.
  6. ClientTransport initiates sending shutdown. For TCP/IP, underlying socket API sends FIN packet.
  7. ClientTransport raises ShutdownCompleted event.