Youāre welcome. Do you have a system to compile it on?
I can send you win32 binaries if you want.
No need, I just wanted to scan the headers and sources. Looks like some
convenience wrappers around the BSD Sockets calls ā pretty much what
you advertised.
Iāve attached the header file for my network abstraction layer ā which
works on MacOS (MacTCP, OpenTransport, AppleTalk), sockets, and WinSock.
I still need to add Serial and IPX support, but the framework is in place.
Sorry, but the source isnāt available ā weāre still trying to work out the
licensing details, but most likely itāll be commercial instead of freebie.
I call it Light Sockets, more as a play on words than anything, as the API
doesnāt really relate to BSD Sockets.
Matt
/* Matt Slot, Bitwise Operator * One box, two box, yellow box, blue box. *
/* File ālsockets.hā, Light Sockets - Copyright Ā© Matt Slot, 1996-7 /
/ Public file that has the relevant declarations to use Light Sockets. */
#ifndef LIGHT_SOCKETS_HEADER
#define LIGHT_SOCKETS_HEADER
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Preprocessor Includes */
#ifndef STANDARD_TYPES_HEADER
#include āstdtypes.hā
#endif /* STANDARD_TYPES_HEADER */
#ifndef STANDARD_ERROR_HEADER
#include āstderror.hā
#endif /* STANDARD_ERROR_HEADER */
#ifndef PLATFORM_HEADER
#include āplatform.hā
#endif /* PLATFORM_HEADER */
#if defined(PLATFORM_MACINTOSH)
#include <Timer.h>
#include <OpenTransport.h>
#elif defined(PLATFORM_UNIX)
#include <sys/types.h>
#include <sys/socket.h>
#endif
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Functional Summary */
/*
Light Sockets provides a lightweight abstraction layer for networking routines.
It offers asynchronous throughput, interrupt-safe send or receive routines, and
callback, polled, or synchronous data access. Network endpoints, addresses, and
queues are managed using opaque data types to encourage platform independence.
This header is the primary public interface for Light Sockets, so it contains
alot of declarations. Please refer to the accompanying documentation for more
information, contextual overviews, and function descriptions.
This file is broken into 4 sections: fundamental types and enumerations,
address structures, data element structures, and public function prototypes.
*/
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Preprocessor Declarations */
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Structure/Class Declarations */
typedef UInt16 NetworkElemType;
enum {
eNetworkElemCustom = 0,
eNetworkElemResolver = 1,
eNetworkElemDatagram = 2,
eNetworkElemStream = 3
};
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef UInt16 NetworkStackType;
typedef UInt32 NetworkStackMaskType;
enum {
eNetworkStackTCPIP = 0,
eNetworkStackATalk = 1,
eNetworkStackTCPIPBit = eNetworkStackTCPIP,
eNetworkStackATalkBit = eNetworkStackATalk,
eNetworkStackTCPIPMask = (1L << eNetworkStackTCPIPBit),
eNetworkStackATalkMask = (1L << eNetworkStackATalkBit),
eNetworkStackAllMask = eNetworkStackTCPIPMask | eNetworkStackATalkMask
};
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef UInt16 NetworkStatusType;
enum {
eNetworkStatusClosed = 0,
eNetworkStatusListening = 1,
eNetworkStatusAccepting = 2,
eNetworkStatusConnecting = 3,
eNetworkStatusTransfer = 4,
eNetworkStatusLocalClose = 5,
eNetworkStatusRemoteClose = 6
};
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef UInt16 NetworkEventType;
typedef UInt32 NetworkEventMaskType;
enum {
/* Network endpoint events */
eNetworkEventFirst = 0,
eNetworkEventIdle = 1,
eNetworkEventLast = 2,
/* Network operation events */
eNetworkEventResolveData = 8,
eNetworkEventResolveDone = 9,
eNetworkEventSendDone = 10,
eNetworkEventSendFailed = 11,
eNetworkEventRecvData = 12,
eNetworkEventRecvXData = 13,
eNetworkEventFlood = 14,
eNetworkEventServer = 15,
eNetworkEventTransfer = 16,
eNetworkEventClosing = 17,
/* Application defined events */
eNetworkEventCustomFirst = 24,
eNetworkEventCustomLast = 31,
/* Corresponding bitfield values */
eNetworkEventFirstBit = eNetworkEventFirst,
eNetworkEventIdleBit = eNetworkEventIdle,
eNetworkEventLastBit = eNetworkEventLast,
eNetworkEventResolveDataBit = eNetworkEventResolveData,
eNetworkEventResolveDoneBit = eNetworkEventResolveDone,
eNetworkEventSendDoneBit = eNetworkEventSendDone,
eNetworkEventSendFailedBit = eNetworkEventSendFailed,
eNetworkEventRecvDataBit = eNetworkEventRecvData,
eNetworkEventRecvXDataBit = eNetworkEventRecvXData,
eNetworkEventFloodBit = eNetworkEventFlood,
eNetworkEventServerBit = eNetworkEventServer,
eNetworkEventTransferBit = eNetworkEventTransfer,
eNetworkEventClosingBit = eNetworkEventClosing,
/* Corresponding bitfield masks */
eNetworkEventFirstMask = (1L << eNetworkEventFirstBit),
eNetworkEventIdleMask = (1L << eNetworkEventIdleBit),
eNetworkEventLastMask = (1L << eNetworkEventLastBit),
eNetworkEventResolveDataMask = (1L << eNetworkEventResolveDataBit),
eNetworkEventResolveDoneMask = (1L << eNetworkEventResolveDoneBit),
eNetworkEventSendDoneMask = (1L << eNetworkEventSendDoneBit),
eNetworkEventSendFailedMask = (1L << eNetworkEventSendFailedBit),
eNetworkEventRecvDataMask = (1L << eNetworkEventRecvDataBit),
eNetworkEventRecvXDataMask = (1L << eNetworkEventRecvXDataBit),
eNetworkEventFloodMask = (1L << eNetworkEventFloodBit),
eNetworkEventServerMask = (1L << eNetworkEventServerBit),
eNetworkEventTransferMask = (1L << eNetworkEventTransferBit),
eNetworkEventClosingMask = (1L << eNetworkEventClosingBit),
};
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef UInt32 NetworkControlMessageType;
typedef UInt32 NetworkControlFlagsType;
enum {
/* Network stack messages */
eNetworkControlStackFirst = 0x00000000,
eNetworkControlStackLast = 0x00001FFF,
/* Suggest that our network stack make aggressive use of memory when
allocating internal buffers (for the stack and its endpoints). The
effects of this message will vary by platform, but the value passed
in flags should indicate an approximate memory footprint (in bytes)
or 0 for default. This message is supported on TCP/IP and AppleTalk
network stacks. */
eNetworkControlStackAggressive = 0x00000000,
/* Enable packet delivery between endpoints on the localhost (Note:
no way has been provided to disable the feature). This message
is supported on AppleTalk network stack. */
eNetworkControlStackSelfSend = 0x00020000,
/* Return a list of zones on the AppleTalk network, where data is a
char ** (the address of a char *) and flags indicate which zones to
return. The function allocates a packed struct of zero-terminated C
strings, and returns the pointer to them in the data parameter. This
message is supported on AppleTalk network stack. */
eNetworkControlStackGetZones = 0x00020001,
eNetworkControlFlagsGetMyZone = 0x00000000,
eNetworkControlFlagsGetLocalZones = 0x00000001,
eNetworkControlFlagsGetFullZones = 0x00000002,
/* Common endpoint messages */
eNetworkControlEndpointFirst = 0x00002000,
eNetworkControlEndpointLast = 0x00003FFF,
/* Enable name binding for a data endpoint (via NBP), where flags is 1
to indicate enabling or 0 for disabling, and data points to a zero
terminated string. To request specific service name, pass the object
and type name string (eg, "xxx:yyy"); to use automatically use the
workstation's "flagship" name, use the object wildcard (eg, "=:yyy").
This message is supported on AppleTalk network stack. */
eNetworkControlEndpointName = 0x00022000,
/* Resolver endpoint messages */
eNetworkControlResolveFirst = 0x00004000,
eNetworkControlResolveLast = 0x00005FFF,
/* Enable multiple results for resolve and lookup calls where flags is
the maximum number of results (0 = unlimited, 1 = default). This
message is supported on TCP/IP and AppleTalk resolver endpoints. */
eNetworkControlResolveMultiple = 0x00004000,
/* Datagram endpoint messages */
eNetworkControlDatagramFirst = 0x00006000,
eNetworkControlDatagramLast = 0x00007FFF,
/* Enable reporting of failed datagram sends due to network failures.
(Flags field should be 1 to enable, 0 to disable). This message
is supported on TCP/IP and AppleTalk datagram endpoints. */
eNetworkControlDatagramFailures = 0x00006000,
/* Retreive the hostmask used for calculating broadcast addresses
into the NetworkAddress structure referenced by data (an empty
address for "no support"). This message is supported on *active*
TCP/IP and AppleTalk datagram endpoints. */
eNetworkControlDatagramHostMask = 0x00006001,
/* Stream endpoint messages */
eNetworkControlStreamFirst = 0x00008000,
eNetworkControlStreamLast = 0x00009FFF,
/* Application defined messages */
eNetworkControlCustomFirst = 0x0000C000,
eNetworkControlCustomLast = 0x0000FFFF
};
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Opaque network address data structure ā only length and raw bytes visible */
typedef struct NetworkAddress {
UInt32 length;
Byte8 bytes[256];
} NetworkAddress, *NetworkAddressPtr;
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef void *NetworkEndpointRef;
typedef void *NetworkResolverRef;
typedef void *NetworkDatagramRef;
typedef void *NetworkStreamRef;
typedef PASCAL void (*NetworkCallbackProc)(NetworkEndpointRef ref, void *refcon,
NetworkEventType event);
#define kNetworkCallbackSetSemaphore ((NetworkCallbackProc)(-1))
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
/* Public network data structures ā application is free to modify fields */
typedef struct ResolverElem {
QStub qstub;
void * refcon;
NetworkAddress address;
Char8 name[ARBITRARY_BUFFER_SIZE];
} ResolverElem, *ResolverElemPtr;
typedef struct DatagramElem {
QStub qstub;
void * refcon;
NetworkAddress address;
UInt32 maxLen;
UInt32 actLen;
Byte8 data[ARBITRARY_BUFFER_SIZE];
} DatagramElem, *DatagramElemPtr;
typedef struct StreamElem {
QStub qstub;
void * refcon;
UInt32 maxLen;
UInt32 actLen;
Byte8 data[ARBITRARY_BUFFER_SIZE];
} StreamElem, *StreamElemPtr;
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
typedef PASCAL UInt32 (*NetworkBufferProc)(NetworkEndpointRef ref, void *refcon,
StreamElemPtr elem,Bool8 expedited);
#define kNetworkBufferBreakOnCRLF ((NetworkBufferProc)(-1))
#define kNetworkBufferBreakOnNull ((NetworkBufferProc)(-2))
#define kNetworkBufferFillBuffers ((NetworkBufferProc)(-3))
#define kNetworkBufferLengthPrefix ((NetworkBufferProc)(-4))
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Function Prototypes */
#ifdef __cplusplus
extern āCā {
#endif
/* High-level network routines */
EXTERN PASCAL Result32 NetworkStackLoad(NetworkStackMaskType stacks);
EXTERN PASCAL void NetworkStackUnload(void);
EXTERN PASCAL void NetworkStackTickle(void);
EXTERN PASCAL Result32 NetworkStackControl(NetworkStackType stack, void *data,
NetworkControlMessageType message,
NetworkControlFlagsType flags);
EXTERN PASCAL Bool8 NetworkStackGetAvail(NetworkStackType stack);
EXTERN PASCAL Bool8 NetworkStackGetActive(NetworkStackType stack);
EXTERN PASCAL Bool8 NetworkStackGetLoaded(NetworkStackType stack);
EXTERN PASCAL Result32 NetworkStackGetSelfAddress(NetworkStackType stack,
NetworkAddressPtr address);
EXTERN PASCAL void NetworkMakeCallback(NetworkCallbackProc callback,
void *refcon,
NetworkEndpointRef ref,
NetworkEventType event);
EXTERN PASCAL Result32 NetworkQueueFill(Queue *queue, NetworkElemType elemType,
UInt32 elemCount, UInt32 elemLen);
EXTERN PASCAL void NetworkQueueEmpty(Queue *queue);
EXTERN PASCAL QStubPtr NetworkQueuePoll(Queue *queue);
EXTERN PASCAL QStubPtr NetworkQueueWait(Queue *queue, UInt32 seconds);
EXTERN PASCAL NetworkElemType
EndpointGetElem(NetworkEndpointRef ref);
EXTERN PASCAL NetworkStackType
EndpointGetStack(NetworkEndpointRef ref);
EXTERN PASCAL NetworkStatusType
EndpointGetStatus(NetworkEndpointRef ref);
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Resolver-based network routines */
EXTERN PASCAL NetworkResolverRef
ResolverCreate (NetworkStackType stack, void *refcon,
NetworkCallbackProc callbackProc,
Queue *doneQueue, Queue *freeQueue);
EXTERN PASCAL void ResolverTickle (NetworkResolverRef ref);
EXTERN PASCAL void ResolverDispose (NetworkResolverRef ref);
EXTERN PASCAL Result32 ResolverControl (NetworkResolverRef ref, void *data,
NetworkControlMessageType message,
NetworkControlFlagsType flags);
EXTERN PASCAL Result32 ResolverOpen (NetworkResolverRef ref);
EXTERN PASCAL Result32 ResolveName (NetworkResolverRef ref,
ResolverElemPtr elem);
EXTERN PASCAL Result32 LookupName (NetworkResolverRef ref,
ResolverElemPtr elem);
EXTERN PASCAL void ResolverClose (NetworkResolverRef ref);
EXTERN PASCAL Result32 SimpleResolve (NetworkStackType stack,Char8 *hostname,
NetworkAddressPtr address);
EXTERN PASCAL Result32 SimpleLookup (NetworkAddressPtr address,
Char8 *hostname);
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Datagram-based network routines */
EXTERN PASCAL NetworkDatagramRef
DatagramCreate(NetworkStackType stack, void *refcon,
NetworkCallbackProc callbackProc,
Queue *doneQueue, Queue *freeQueue,
Queue *recvQueue,Queue *recvXQueue);
EXTERN PASCAL void DatagramTickle (NetworkDatagramRef ref);
EXTERN PASCAL void DatagramDispose (NetworkDatagramRef ref);
EXTERN PASCAL Result32 DatagramControl (NetworkDatagramRef ref, void *data,
NetworkControlMessageType message,
NetworkControlFlagsType flags);
EXTERN PASCAL Result32 DatagramOpen (NetworkDatagramRef ref,
NetworkAddressPtr localAddress);
EXTERN PASCAL Result32 DatagramSend (NetworkDatagramRef ref,
DatagramElemPtr elem);
EXTERN PASCAL void DatagramClose (NetworkDatagramRef ref, Bool8 orderly);
EXTERN PASCAL Result32 DatagramGetAddress(NetworkDatagramRef ref,
NetworkAddressPtr localAddress);
EXTERN PASCAL Bool8 DatagramGetFailedAddress(NetworkDatagramRef ref,
NetworkAddressPtr remoteAddress);
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Stream-based network routines */
EXTERN PASCAL NetworkStreamRef
StreamCreate(NetworkStackType stack, void *refcon,
NetworkCallbackProc callbackProc,
Queue *doneQueue, Queue *freeQueue,
Queue *recvQueue,Queue *recvXQueue);
EXTERN PASCAL NetworkStreamRef
StreamCreateBuffered(NetworkStackType stack,
void *refcon,
NetworkCallbackProc callbackProc,
NetworkBufferProc bufferProc,
Queue *doneQueue, Queue *freeQueue,
Queue *recvQueue,Queue *recvXQueue);
EXTERN PASCAL void StreamTickle (NetworkStreamRef ref);
EXTERN PASCAL void StreamDispose (NetworkStreamRef ref);
EXTERN PASCAL Result32 StreamControl (NetworkStreamRef ref, void *data,
NetworkControlMessageType message,
NetworkControlFlagsType flags);
EXTERN PASCAL Result32 StreamOpenServer(NetworkStreamRef ref,
NetworkAddressPtr localAddress);
EXTERN PASCAL Result32 StreamAcceptServer(NetworkStreamRef serverRef,
NetworkStreamRef acceptRef);
EXTERN PASCAL Result32 StreamOpenClient(NetworkStreamRef ref,
NetworkAddressPtr localAddress,
NetworkAddressPtr remoteAddress);
EXTERN PASCAL Result32 StreamSend (NetworkStreamRef ref,
StreamElemPtr elem);
EXTERN PASCAL void StreamClose (NetworkStreamRef ref, Bool8 orderly);
EXTERN PASCAL Result32 StreamGetAddress(NetworkStreamRef ref,
NetworkAddressPtr localAddress,
NetworkAddressPtr remoteAddress);
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ Network Address abstraction routines */
EXTERN PASCAL NetworkStackType
AddressToNetworkStack(NetworkAddressPtr addressPtr);
EXTERN PASCAL void AddressFromNetworkStack(NetworkAddressPtr addressPtr,
NetworkStackType stack);
EXTERN PASCAL void AddressDuplicate (NetworkAddressPtr dst,
NetworkAddressPtr src);
EXTERN PASCAL Bool8 AddressBroadcast (NetworkAddressPtr dst,
NetworkAddressPtr src,
NetworkAddressPtr hostmask);
EXTERN PASCAL void AddressIncrement (NetworkAddressPtr addressPtr);
EXTERN PASCAL Bool8 AddressCompare (NetworkAddressPtr addr1,
NetworkAddressPtr addr2);
EXTERN PASCAL Bool8 AddressIsEmpty (NetworkAddressPtr addressPtr);
EXTERN PASCAL void AddressComposeEmpty (NetworkAddressPtr addressPtr);
EXTERN PASCAL void AddressComposeTCPIP (NetworkAddressPtr addressPtr,
UInt16 port, UInt32 host);
EXTERN PASCAL void AddressComposeATalk (NetworkAddressPtr addressPtr,
UInt16 netID, UInt8 nodeID,
UInt8 sockID, UInt8 sockType);
EXTERN PASCAL void AddressDecomposeTCPIP(NetworkAddressPtr addressPtr,
UInt16 *port, UInt32 *host);
EXTERN PASCAL void AddressDecomposeATalk(NetworkAddressPtr addressPtr,
UInt16 *netID, UInt8 *nodeID,
UInt8 *sockID, UInt8 *sockType);
EXTERN PASCAL void AddressTranscribe(NetworkAddressPtr addressPtr,
Char8 *textPtr);
EXTERN PASCAL Result32 AddressPicker (Char8 *message,
NetworkStackMaskType stacks,
NetworkAddressPtr address,
Char8 *hostname, Char8 *hosttype);
#ifdef __cplusplus
}
#endif
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** /
/ **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
#endif /* LIGHT_SOCKETS_HEADER */