Search code examples
objective-ccocoasocketsmacos-carbon

CFSocketSetAddress fails


I have a problem with CFSocketSetAddress(). The first time I call it, it works just fine. If I clean up everything associated with the socket and attempt to open it again on the same port I get a CFSocketError of -1 (kCFSocketError - very descriptive).

I'm presuming I didn't clean up the previous socket correctly. I'm cleaning up all the FileDescriptors and calling CFSocketInvalidate and CFRelease on the CFSocketRef. Is there anything else I need to do to clean up the existing socket so that the socket can be reopened?


Solution

  • Ok this always happens. Post to StackOverflow and then figure it out about 5 mins later.

    Answer: I needed to call closeFile on the NSFileHandle associated with the socket.