| 1375 | |
| 1376 | |
| 1377 | void SocketManager::finalize() |
| 1378 | { |
| 1379 | // We require the `SocketManager` to be finalized after the server socket |
| 1380 | // has been closed. This means that no further incoming sockets will be |
| 1381 | // given to the `SocketManager` at this point. |
| 1382 | CHECK(__s__ == nullptr); |
| 1383 | |
| 1384 | // We require all processes to be terminated prior to finalizing the |
| 1385 | // `SocketManager`. This simplifies the finalization logic as we do not |
| 1386 | // have to worry about sockets or links being created during cleanup. |
| 1387 | // |
| 1388 | // TODO(benh): can't do the following anymore, need another way: |
| 1389 | // |
| 1390 | // CHECK(gc == nullptr); |
| 1391 | |
| 1392 | int_fd socket = -1; |
| 1393 | // Close each socket. |
| 1394 | // Don't hold the lock since there is a dependency between `SocketManager` |
| 1395 | // and `ProcessManager`, which may result in deadlock. See comments in |
| 1396 | // `SocketManager::close` for more details. |
| 1397 | do { |
| 1398 | synchronized (mutex) { |
| 1399 | socket = !sockets.empty() ? sockets.begin()->first : -1; |
| 1400 | } |
| 1401 | |
| 1402 | if (socket >= 0) { |
| 1403 | // This will also clean up any other state related to this socket. |
| 1404 | close(socket); |
| 1405 | } |
| 1406 | } while (socket >= 0); |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | void SocketManager::accepted(const Socket& socket) |