static void ReceiveLoop(NWConnection connection) { connection.ReceiveData(1, uint.MaxValue, (DispatchData dispatchData, NWContentContext context, bool isComplete, NWError error) => { Action scheduleNext = () => { // If the context is marked as complete, and is the final context, // we're read-closed. if (isComplete) { if (context != null && context.IsFinal) { if (verbose) { warn("Exiting because isComplete && context.IsFinal"); } Environment.Exit(0); } if (dispatchData == null) { if (verbose) { warn($"Exiting because isComplete && data == zero; error={error}"); } Environment.Exit(0); } } if (error == null) { ReceiveLoop(connection); } }; if (dispatchData != null) { const int STDOUT_FILENO = 1; DispatchIO.Write(STDOUT_FILENO, dispatchData, DispatchQueue.MainQueue, (data, stdoutError) => { if (stdoutError != 0) { warn("stdout write error"); } scheduleNext(); }); } else { scheduleNext(); } }); }