mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
* NIO: implement `cleanupSocket(unixDomainSocketPath:)` for Windows This adds an initial implementation for the UDS clean up path on Windows. Unlike Unix, you cannot simply `stat` the destination to determine if it is a UDS endpoint. One must first create a file handle from the path. Assuming that we are able to create that, we should verify that the file that we are dealing with is a not a disk type as the subsequent checks will fail. Now, we can use the file handle to query the information of the file. This will allow us to determine if it is a reparse point. If not, it is impossible for it to be a UDS as a UDS endpoint is a reparse point with the tag IO_REPARSE_TAG_AF_UNIX. Once we know that we have a reparse point, we must query the kernel for information about it via the `DeviceIoControl` system call (perform an ioctl in Unix speak). The returned buffer's tag will identify if we have a UDS. For the next dance, we must now _close_ the handle as the handle being left open will cause the subsequent `DeleteFileW` to fail due to there being an open handle. Once we have cleaned up the file handle that we created, we can safely attempt to remove the file via `DeleteFileW`. This should hopefully be sufficiently robust from possible error scenarios for the removal of a UDS endpoint. * NIO: improve the UDS cleanup path on Windows Instead of doing the complex close-handle dance, instead prefer `SetFileInformationByHandle` which: 1. avoids a second UTF-8 -> UCS-2 conversion 2. avoids the need for the handle closing dance 3. avoids a third re-query of the handle 4. enables us to use "POSIX" deletion semantics (file is immediately removed from the namespace but data streams are left intact) This comes at the cost of being Windows 10 centric, which I find a reasonable trade-off as Windows 7 has been EOL'ed by Microsoft, and more importantly, Unix Domain Sockets are only available on Windows 10! Thanks to @adierking for the reminder about SetFileInformationByHandle!