Swift 3 and BSD Sockets

A number of folks have asked me about how best to deal with BSD Sockets APIs in the new world of Swift raw pointers (SE-0107). Over on swift-users I wrote:

In my case I … added a method … that calls a closure with the right parameters (actually, multiple such methods, depending on whether I’m calling something like

connect
which takes an address, or
getpeername
, which returns one). This approach concentrates all the ugly in one place, making the rest of my BSD Sockets code much cleaner.

I’ve been revisiting this issue recently and decided to tidy up my code enough to share with others. I posted it here.

Bon apétit!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"