@@ -98,11 +98,11 @@ extension TCPSocket {
9898
9999 var res = getaddrinfo ( hostname, port. description, & hints, & result)
100100 guard res == 0 else {
101- throw TCPError . posix (
102- errno ,
101+ throw TCPError . gaierrno (
102+ res ,
103103 identifier: " getAddressInfo " ,
104104 possibleCauses: [
105- " The address that binding was attempted on does not refer to your machine. "
105+ " The address that binding was attempted on ( \" \( hostname ) \" : \( port ) ) does not refer to your machine."
106106 ] ,
107107 suggestedFixes: [
108108 " Bind to `0.0.0.0` or to your machine's IP address "
@@ -165,3 +165,36 @@ extension TCPSocket {
165165 }
166166}
167167
168+ extension TCPError {
169+ static func gaierrno(
170+ _ gaires: Int32 ,
171+ identifier: String ,
172+ possibleCauses: [ String ] = [ ] ,
173+ suggestedFixes: [ String ] = [ ] ,
174+ file: String = #file,
175+ function: String = #function,
176+ line: UInt = #line,
177+ column: UInt = #column
178+ ) -> TCPError {
179+ guard gaires != EAI_SYSTEM else {
180+ return . posix(
181+ errno,
182+ identifier: identifier,
183+ possibleCauses: possibleCauses,
184+ suggestedFixes: suggestedFixes,
185+ file: file, function: function, line: line, column: column)
186+ }
187+ let message = COperatingSystem . gai_strerror ( gaires)
188+ let string = String ( cString: message!, encoding: . utf8) ?? " unknown "
189+ return TCPError (
190+ identifier: identifier,
191+ reason: string,
192+ possibleCauses: possibleCauses,
193+ suggestedFixes: suggestedFixes,
194+ file: file,
195+ function: function,
196+ line: line,
197+ column: column
198+ )
199+ }
200+ }
0 commit comments