%
% Aberdeen's universal socket front-end
%
% 30-Jan-2002	1)	I'm removing Quintus compatibility as it is no
%			longer supported in our dept.
%		2)	"sockets.pl" is renamed to "a_sockets.pl" to
%			distinguish from SICStus's original socket lib. (KH)
%		3)	socket_select/4 added because of the limitation in SICStus.
%
% Modified for ECLiPSe 5 on 20/02/2001
% losing 3.6.1 compatibility, by K. Hui
%
% Remarks:
%
% In ECLiPSe 3.6.1, you have to load the SICStus compatibility
% library before you can use module/2 to start a module.
% This seems to be changed in ECLiPSe 5.0 and above.
% So it is no longer needed to consult 'util/for_eclipse'.
%

:- module(a_sockets,[	a_socket_create/2,	%create a socket
			a_socket_destroy/1,	%destroy a socket
			a_socket_bind/2,	%bind a socket to a name
			a_socket_listen/2,	%listen and set queue length
			a_socket_accept/4,	%accept incoming connection to a socket
			a_socket_connect/4,	%connect to remote
			a_socket_select/4,	%select ready socket/stream
			a_socket_select/7,	%select between fds
			a_hostname/1		%get current hostname
			]).

:- ['../util/prolog_detect'].		%load Prolog detecting module

% load the "flatten" module for SICStus & Quintus
% no need for SWI & ECLiPSe
%
:- prolog_detect:prolog(Prolog),
	(	(	Prolog=sicstus,
			use_module('../util/flatten')
		);
		(	Prolog=eclipse,
			use_module(library(iso))	%***ISO compatibility for ECLiPSe 5
		);
		(	Prolog=swi
		);
		(	Prolog=quintus,
			write('*** Quintus Prolog is no longer supported!!!***'),
			nl,
			!,
			fail
		)
	).

%
% load the correct Prolog source according to machine-type & Prolog platform
%
:-	prolog_detect:prolog(System),			%get Prolog type
	(	(System=pfdm,!,Prolog=sicstus);
		System=Prolog
	),
	name(Prolog,S1),
	name(sockets,S2),
	flatten([S1,"_",S2,"/",S1,"_",S2],S),		%compose pathname string
	name(File,S),
	[File].						%continue loading file
