/*
 *  File Name:			ipc.h
 *  Purpose:			Declarations for IPC routines.
 *  Created:			10 Dec 88
 *  Last Modified:		29 Jun 90
 *  Comments:
 *  History:
 *		02 Jan 89	Added accept/broadcast functions and IPC_ADDRESS.
 *		09 Oct 89	Fake FD_SET et. al. to work like pre-SunOS 4.0 select()
 *					expects.  Some 3.4 systems have fd_set typedef'ed in
 *					<sys/types.h> but not used anywhere.  Define BOGUS_FD_SET
 *					for such rude systems.
 *		29 Jun 90	FD_SETSIZE should be size of an integer in bits,
 *					not bytes.
 */

# ifndef	bah_ipc_library
# define	bah_ipc_library

# ifdef BOGUS_FD_SET
# define	fd_set		bogus_fd_set	/* defeat sys/types.h typedef */
# endif

# include	<sys/types.h>

# ifdef BOGUS_FD_SET
# undef	fd_set
# endif

/*
 *	If the SunOS 4.0 FD macros for select() aren't defined, we will assume
 *	the older select() is the only one available.  Accordingly, we fake the
 *	FD macros to work the way the old select() expects.
 */

# ifndef FD_SETSIZE

# define	FD_SETSIZE			( 32 )

typedef int		fd_set;

# define	FD_ZERO( p )		*(p) = 0;
# define	FD_SET( fd, p )		*(p) |= 1 << (fd);
# define	FD_CLR( fd, p )		*(p) &= ~( 1 << (fd) )
# define	FD_ISSET( fd, p )	( (*(p)) & ( 1 << (fd) ) )

# endif


typedef int		PORT;		/* IPC facility identifiers use this type */

typedef struct {
	char		*host_name;	/* machine name of host */
	int			handle; 	/* address within machine (port number for */
							/* Internet style) */
	} IPC_ADDRESS;


PORT ipc_create(int id);

int ipc_connect(IPC_ADDRESS addr, PORT *output, PORT *input);

int ipc_accept(PORT gate, IPC_ADDRESS *addr, PORT *input, PORT *output);

int ipc_send(PORT port, u_char *data, u_int length);

int ipc_recv(PORT port, u_char *data, u_int max);

int ipc_recvs(PORT port, char *str, int max);

int ipc_sends(PORT port, char *str);

int ipc_wait(fd_set *ports);

int ipc_wait_stdin(fd_set *ports);

void ipc_release(PORT port);

int ipc_poll(fd_set *readports, fd_set *writeports);

# if _AMIGA

# define	INTUI_V36_NAMES_ONLY		/* removes some bogus defines */

# include	<intuition/intuition.h>

void ipc_timer(void (*fn)(), int sig);
void ipc_set_stdin(struct MsgPort *msgport);

# endif


# endif
