Skip to content

Commit

Permalink
Ensure Unix domain socket path does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
djones6 committed Mar 29, 2019
1 parent f1c0489 commit f04d4eb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/KituraNet/HTTP/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import LoggerAPI
import NIOWebSocket
import CLinuxHelpers

#if os(Linux)
import Glibc
#else
import Darwin
#endif

// MARK: HTTPServer
/**
An HTTP server that listens for connections on a socket.
Expand Down Expand Up @@ -306,6 +312,12 @@ public class HTTPServer: Server {
serverChannel = try bootstrap.bind(host: "0.0.0.0", port: port).wait()
case SocketType.unix(let unixDomainSocketPath):
listenerDescription = "path \(unixDomainSocketPath)"
// Ensure the path doesn't exist...
#if os(Linux)
_ = Glibc.unlink(unixDomainSocketPath)
#else
_ = Darwin.unlink(unixDomainSocketPath)
#endif
serverChannel = try bootstrap.bind(unixDomainSocketPath: unixDomainSocketPath).wait()
}
self.port = serverChannel?.localAddress?.port.map { Int($0) }
Expand Down

0 comments on commit f04d4eb

Please sign in to comment.