/*<ATGCOPYRIGHT>
 * Copyright (C) 2000 Art Technology Group, Inc.
 * All Rights Reserved.  No use, copying or distribution of this
 * work may be made except in accordance with a valid license
 * agreement from Art Technology Group.  This notice must be
 * included on all copies, modifications and derivatives of this
 * work.
 *
 * Art Technology Group (ATG) MAKES NO REPRESENTATIONS OR WARRANTIES 
 * ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ATG SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, 
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * "Dynamo" is a trademark of Art Technology Group, Inc.
 </ATGCOPYRIGHT>*/

/*
  DynSock.h - public API for Socket adaption
*/

#ifndef _DYN_SOCK_H_
#define _DYN_SOCK_H_

#ifdef WIN32
/* NT */
#include <windows.h>
#include <winsock.h>
#else
/* UN?X */
#include <sys/types.h>
#include <sys/socket.h>

#include <errno.h>
#endif

/* socket_t: abstracted socket type for WIN32 & UNIXen */
#ifdef WIN32
typedef SOCKET          socket_t;
#else
typedef int             socket_t;
#endif

/* struct used in creation of socket */
typedef struct _dynSocketInfo {
    void *info;                    /* Info used in creation of socket */
} dynSocketInfo;

/* struct used to represent a socket */
typedef struct _dynSocket {
    char version[24];              /* version identification     */
    dynSocketInfo *info;           /* pointer to socket info     */ 
    void *socket_data;             /* pointer to raw socket data */
    int connected;                 /* is this socket connected   */
    struct sockaddr remote_addr;   /* remote host address        */
    int remote_addr_len;           /* remote host address len    */
}dynSocket;

/* Initialization Routines */
int dynSocket_init(void *pInitData);

/* Socket Communication Routines */
#ifdef _ISAPI
dynSocket *dynSocket_new(HANDLE gHeap, dynSocketInfo *pInfo);
int dynSocket_close(HANDLE gHeap, dynSocket *pDynSocket);
#else
dynSocket *dynSocket_new(dynSocketInfo *pInfo);
int dynSocket_close(dynSocket *pDynSocket);
#endif
int dynSocket_connect(dynSocket *pDynSocket,struct sockaddr *pRemoteAddr,int pLen);
int dynSocket_read(dynSocket *pDynSocket,void *pBuf,size_t pCount);
int dynSocket_write(dynSocket *pDynSocket,const void *pBuf,size_t pCount);
int dynSocket_recv(dynSocket *pDynSocket, void *pBuf,int pLen,int pFlags);
int dynSocket_send(dynSocket *pDynSocket,const void *pMsg,int len,int pFlags);

/* DynSock Properties */
char *dynSocket_version(dynSocket *pDynSocket);
dynSocketInfo *dynSocket_info(dynSocket *pDynSocket);
void *dynSocket_socket_data(dynSocket *pDynSocket);
int dynSocket_connected(dynSocket *pDynSocket);
struct sockaddr *dynSocket_remote_addr(dynSocket *pDynSocket);
int dynSocket_remote_addr_len(dynSocket *pDynSocket);
socket_t dynSocket_socket(dynSocket *pDynSocket);


#endif /* _DYN_SOCK_H_ */
