#ifndef __DWC_UNIX_H
#define __DWC_UNIX_H

/*--------------------------------------------------------------------------
 *  Copyright (c) 2001-2004 Igor Daniloff. 
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at this directory.
 *------------------------------------------------------------------------*/
 
/* $Id: dwc_unix.h,v 1.17 2005/09/21 09:20:44 asv Exp $ */

#if defined(__UNIX_DW)

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#include "dwc_timo.h"
#include "dwc_type.h"

#ifdef  __cplusplus
extern "C" {
#endif

#define INVALID_UNIX_SOCKET    (-1)

typedef int                  DWC_unix_socket_t;
typedef struct sockaddr_un   DWC_unix_socket_addr_t;

#else  /* !UNIX || EMX */

#include "dwc_timo.h"
#include "dwc_type.h"

/* It's fake structures not a real */
typedef int                  DWC_unix_socket_t;
typedef struct {
    int   sun_family;
    char  sun_path[1];   
}                            DWC_unix_socket_addr_t;

#endif /* __UNIX_DW */

extern DWC_error_code_t init_unix_sockets ( void );
extern DWC_error_code_t dinit_unix_sockets ( void );
extern DWC_error_code_t create_unix_socket( DWC_unix_socket_t *sock, DWC_bool_t nonblocking );
extern DWC_error_code_t bind_unix_socket ( DWC_unix_socket_t sock, DWC_unix_socket_addr_t* addr );
extern DWC_error_code_t listen_unix_socket ( DWC_unix_socket_t sock, int backlog );
extern DWC_error_code_t accept_unix_socket ( DWC_unix_socket_t sock, DWC_unix_socket_addr_t *addr, DWC_unix_socket_t *newsock );
extern DWC_error_code_t connect_unix_socket ( DWC_unix_socket_t sock, DWC_unix_socket_addr_t *addr, DWC_timeout_t timeout );
extern DWC_error_code_t send_unix_socket ( DWC_unix_socket_t *sock, DWC_pointer_t buf, DWC_length_t *len, DWC_timeout_t timo );
extern DWC_error_code_t recv_unix_socket ( DWC_unix_socket_t *sock, DWC_pointer_t buf, DWC_length_t* len_ptr, int options );
extern DWC_error_code_t shutdown_unix_socket ( DWC_unix_socket_t *sock, DWC_unix_socket_addr_t addr, DWC_bool_t linked );
extern DWC_error_code_t close_unix_socket ( DWC_unix_socket_t *sock, DWC_unix_socket_addr_t addr, DWC_bool_t linked );
extern dwc_bool_t       fill_unix_addr( const char *path, DWC_unix_socket_addr_t *naddr );

#ifdef  __cplusplus
}
#endif

#endif /* __DWC_UNIX_H */
