/* --- Copyright University of Sussex 1994. All rights reserved. ----------
 > File:            C.unix/src/sockets.p
 > Purpose:
 > Author:          John Gibson May  6 1994
 > Documentation:
 */
;;; ------------------ UNIX SOCKET INTERFACE ------------------------------

#_TERMIN_IF not(DEF BERKELEY or DEFV SYSTEM_V >= 4.0)

#_INCLUDE 'declare.ph'
#_INCLUDE 'unixdefs.ph'


;;; ----------------------------------------------------------------------

section $-Sys$-Io => syssocket;

define syssocket(af, type, protocol, arg3);
	lvars af, arg3, protocol, type, _fd, _retry = _1;
	Check_integer(af, 0);
	Check_integer(type, 0);
	Check_integer(protocol, 0);

	repeat
		_extern socket(_int(af), _int(type), _int(protocol)) -> _fd;
		quitif(_neg(Fd_open_check(_fd, true, _retry) ->> _retry))
	endrepeat;

	if _neg(_fd) then
		Syserr_mishap(af, type, protocol, 3, 'CAN\'T CREATE SOCKET')
	endif;
	Cons_device('socket', false, 2, arg3, _fd, true)
enddefine;

#_IF DEFV SYSTEM_V >= 4.0

	/* socket support is provided in a separate library; do a dummy
	   external load to make sure it's included in the link
	*/
exload socket ['-lsocket']
	lconstant exload_dummy;		;;; anything will do
endexload;

#_ENDIF

endsection;		/* $-Sys$-Io */
