/* begincopyright
  Copyright (c) 1988 Xerox Corporation. All rights reserved.
  Use and copying of this software and preparation of derivative works based
  upon this software are permitted. Any distribution of this software or
  derivative works must comply with all applicable United States export
  control laws. This software is made available AS IS, and Xerox Corporation
  makes no warranty about the software, its performance or its conformity to
  any specification. Any person obtaining a copy of this software is requested
  to send their name and post office or electronic mail address to:
    PCR Coordinator
    Xerox PARC
    3333 Coyote Hill Rd.
    Palo Alto, CA
  endcopyright */
/*
 * CMUXGlue.h
 *
 * XR interface to Mentat Courier Multiplexor
 *
 * Demers, April 25, 1990 8:35:59 am PDT
 */


#ifndef ←XR←CMUX←GLUE←
#define ←XR←CMUX←GLUE←	1


#ifndef ←UIO←
#   include "xr/UIO.h"
#endif


/*
 * CMUX Descriptors
 *
 * Client or Server
 */

typedef XR←Fildes XR←CMUXDescriptor;

#   define XR←nullCMUXDesciptor	((XR←CMUXDescriptor)(-1))

/*
 * Descriptor Create/Destroy
 *
 * Client or Server
 */

extern XR←CMUXDescriptor
XR←CMUXCreate ();
/*
    Create a CMUX descriptor and return it.
    On failure, call XR←SetErrno(why) and return nullCMUXDesciptor.
*/

extern void
XR←CMUXDestroy(/*
    XR←CMUXDescriptor d
*/);
/*
    Close a CMUX descriptor.
*/


/*
 * Descriptor Binding
 *
 * Client Only.
 */

typedef int XR←CMUXAddrType;

#   define XR←CMUX←ADDR←TYPE←DFLT←ADDR	0
#   define XR←CMUX←ADDR←TYPE←DFLT←NAME	1

#   define XR←CMUX←ADDR←TYPE←XNS←ADDR   2
#   define XR←CMUX←ADDR←TYPE←XNS←NAME	3

extern int
XR←CMUXConnect(/*
    XR←CMUXDescriptor d,
    XR←CMUXAddrType type,
    XR←Pointer addr,
    int addrLen
*/);
/*
    Connect client descriptor to server at specified address.
    Return 0.
    On failure, call XR←SetErrno(why) and return(-why).
*/


/*
 * Courier message I/O
 *
 * Client or Server
 */

typedef XR←Pointer (*XR←CMUXAllocaterFunc)(/*
    unsigned startIndex,
    unsigned nBytes,
    XR←Pointer clientData
*/);
/*
    Callback type for XR←CMUXReadMsg below.

    Return pointer to a contiguous buffer area of capacity at least nbytes.
    XR←CMUXReadMsg will store up to nbytes worth of data there, as message
      content in range [startIndex .. startIndex+nbytes).

    The returned pointer is to the startIndex'th byte of message; there
      is no requirement that the entire message be stored contiguously.

    Special Case: startIndex = nBytes = 0 may release buffer and return NIL.
*/


extern int
XR←CMUXReadMsg(/*
    XR←CMUXDescriptor d,
    bool ignoreAborts,
    unsigned timeoutMsec,
    XR←CMUXAllocaterFunc allocaterFunc,
    XR←Pointer allocaterClientData,
*/);
/*
    Read a Courier message, including header.
    Return length.
    On failure, call XR←SetErrno(why) and return (-why). 
*/


extern int
XR←CMUXWriteMsg (/*
    XR←CMUXDescriptor d,
    XR←Pointer hdr,
    unsigned hdrLen,
    XR←Pointer body,
    unsigned bodyLen
*/);
/*
    Write a Courier message with specified header.
    Return 0.
    On failure, call XR←SetErrno(why) and return (-why).
*/



extern int
XR←CMUXBDTRead(/*
    XR←CMUXDescriptor d,
    XR←Pointer buf,
    unsigned nBytes
*/);
/*
    Bulk Data read.
    Return number of bytes actually read, 0 at end of stream.
    On failure (include received abort) call XR←SetErrno(why) and return (-why).
*/


extern int
XR←CMUXBDTWrite(/*
    XR←CMUXDescriptor d,
    XR←Pointer buf,
    unsigned nBytes
*/);
/*
    Bulk Data write.
    Return number of bytes actually written.
    On failure (include received abort) call XR←SetErrno(why) and return (-why).
*/



extern int
XR←CMUXFinishBDT (/*
    XR←CMUXDescriptor d,
    bool source,
    bool sendAbort
*/);
/*
    Bulk Data Transfer abort processing.
    If source is TRUE this side is the bulk data source.
    If sendAbort is TRUE this side is initiating an abort.
    Return 0.
    On failure, call XR←SetErrno(why) and return (-why).
*/

extern int
XR←CMUXServerAdd(/*
    XR←CMUXDescriptor d,
    unsigned pgm,
    unsigned loVersion, hiVersion
*/);
/*
    Set descriptor to be server for given pgm and version range.
    Return 0.
    On failure, call XR←SetErrno(why) and return (-why).
*/


extern int
XR←CMUXServerQuit(/*
    XR←CMUXDescriptor d
*/);
/*
    Set descriptor no longer to be server.
    Return 0.
    On failure, call XR←SetErrno(why) and return (-why).
*/



#endif /* ←XR←CMUX←GLUE← */