+ }
+
+ // Adjust the socket options to suit our needs:
+ CFOptionFlags sockopt = CFSocketGetSocketFlags(cfSocket);
+
+ // First, by default, write callback is not called repeatedly when data
+ // can be written to the socket but we need this behaviour so request
+ // it explicitly.
+ if ( flags & wxEVENT_SOURCE_OUTPUT )
+ sockopt |= kCFSocketAutomaticallyReenableWriteCallBack;
+
+ // Second, we use the socket to monitor the FD but it doesn't own it,
+ // so prevent the FD from being closed when the socket is invalidated.
+ sockopt &= ~kCFSocketCloseOnInvalidate;
+
+ CFSocketSetSocketFlags(cfSocket, sockopt);