Closed tombell closed 2 years ago
I'm not sure why you're getting that error. Perhaps there's a threading issue due to the use of the global queue? I tried a paired down version and it seems to connect ok:
server.swift:
#!/usr/bin/swift sh
import Socket // kitura/BlueSocket
let socketPath = "socket"
let socket = try Socket.create(family: .unix, type: .stream, proto: .unix)
try socket.listen(on: socketPath)
while true {
print("Waiting for connection...")
let client = try socket.acceptClientConnection()
print("Got client: \(client)")
}
print("Done!")
client.swift:
#!/usr/bin/swift sh
import Socket // kitura/BlueSocket
let socketPath = "socket"
let socket = try Socket.create(family: .unix, type: .stream, proto: .unix)
try socket.connect(to: socketPath)
print("Done!")
This makes use of swift-sh
@dannys42 Yeah, it's a complete mystery to me, I made a separate project client and that could connect fine, using socat
could connect fine, but any sort of client inside the same project as the server, it just doesn't seem to work.
Update:
Looks like sometimes it connects, and the majority of the time it fails to accept the connection
Update 2:
After some more debugging with trial and error, a bare separate client executable in the project appeared to connect fine each time.
I then commented everything out in the main executable, except for calling the client to connect and send a hard coded message, and that could connect.
I slowly uncommented code until the error presented itself... and it appears to do with let arguments = Arguments.parseOrExit()
, now I have no idea what that is doing to cause the issue. :joy:
Update 3:
I added swift-argument-parser
to the test project and called parseOrExit
for some test args, and the socket managed to connect, so I'm kind of decuding that the problem must be something with my exectuable target and "library" target.
I've managed to create a simple minimal project that reproduces the issue for me https://github.com/tombell/minimal-socket-bug
Since this doesn't appear to be a bug directly with BlueSocket, and I've managed to figure out a work around, I'll close this off.
Hey @tombell, would you mind sharing your workaround? I'm running into an issue that sounds awfully similar to this.
@mschrage my work around was kind of just splitting things out into functions, and I think wrapping the Socket
function calls in do { ... } catch { ... }
seemed to help to
I'm trying to creaste a listening UNIX socket, and also connect to it using
BlueSocket
, however I'm getting the errorError code: -9993(0x-2709), Invalid argument
when callingsocket.acceptClientConnection()
when connecting usingBlueSocket
, however testing with the utilitysocat
it connects fine.Server code:
Client
I am assuming I am missing something from the connecting side of things.
My project: https://github.com/tombell/swm