"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

//#region src/events/exit/_internal.ts
const globalProcess = globalThis.process;
const originalProcessEmit = globalProcess?.emit;
const platform = globalProcess?.platform ?? "";
const originalProcessReallyExit = globalProcess?.reallyExit;
const WIN32 = platform === "win32";
let _events;
let _emitter;
let _loaded = false;
let _signals;
/* c8 ignore start - Only called from signal-listener body and
processEmit/processReallyExit interceptors, all of which are
c8-ignored. Cannot be reached from the test runner. */
/*@__NO_SIDE_EFFECTS__*/
function emit(event, code, signal) {
	const emitter = /* @__PURE__ */ getEmitter();
	if (emitter.emitted?.[event]) return;
	if (emitter.emitted) emitter.emitted[event] = true;
	emitter.emit(event, code, signal);
}
/* c8 ignore stop */
/*@__NO_SIDE_EFFECTS__*/
function getEmitter() {
	/* c8 ignore start */
	if (_emitter === void 0) {
		if (globalProcess?.__signal_exit_emitter__) _emitter = globalProcess.__signal_exit_emitter__;
		else if (globalProcess) {
			const EventEmitter = (/* @__PURE__ */ getEvents()).EventEmitter;
			_emitter = globalProcess.__signal_exit_emitter__ = new EventEmitter();
			_emitter.count = 0;
			_emitter.emitted = { __proto__: null };
		}
		if (_emitter && !_emitter.infinite) {
			_emitter.setMaxListeners(Number.POSITIVE_INFINITY);
			_emitter.infinite = true;
		}
	}
	/* c8 ignore stop */
	return _emitter;
}
/*@__NO_SIDE_EFFECTS__*/
function getEvents() {
	/* c8 ignore start */
	if (_events === void 0) _events = /*@__PURE__*/ require("node:events");
	/* c8 ignore stop */
	return _events;
}
/**
* Get the cached signal list. Triggers lazy init on first call; after `load()`
* runs it returns the filtered subset of successfully registered signals
* instead of the full default list.
*/
/*@__NO_SIDE_EFFECTS__*/
function getSignals() {
	if (_signals === void 0) {
		_signals = [
			"SIGABRT",
			"SIGALRM",
			"SIGHUP",
			"SIGINT",
			"SIGTERM"
		];
		/* c8 ignore start */
		if (!WIN32) _signals.push("SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
		if (platform === "linux") _signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT", "SIGUNUSED");
	}
	return _signals;
}
/**
* Read the loaded flag from a sibling leaf (lifecycle / on-exit).
*
* @private
*/
function isLoaded() {
	return _loaded;
}
/**
* Set the `loaded` flag from a sibling leaf (load / unload).
*
* @private
*/
function setLoaded(value) {
	_loaded = value;
}
/**
* Replace the cached signal list (used by `load()`'s filter step).
*
* @private
*/
function setSignals(value) {
	_signals = value;
}

//#endregion
exports.WIN32 = WIN32;
exports.emit = emit;
exports.getEmitter = getEmitter;
exports.getEvents = getEvents;
exports.getSignals = getSignals;
exports.globalProcess = globalProcess;
exports.isLoaded = isLoaded;
exports.originalProcessEmit = originalProcessEmit;
exports.originalProcessReallyExit = originalProcessReallyExit;
exports.platform = platform;
exports.setLoaded = setLoaded;
exports.setSignals = setSignals;