#ifndef __DWC_TCP_H
#define __DWC_TCP_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_tcp.h,v 1.22 2005/09/21 09:20:44 asv Exp $ */

#include <stdarg.h>
#include "dwc_type.h"
#include "dwc_timo.h"

#if defined(__cplusplus)
extern "C" {
#endif 

#if defined(__WIN32_DW) 

#include <winsock.h>

typedef SOCKET                  DWC_tcp_socket_t;
#define INVALID_TCP_SOCKET      INVALID_SOCKET
#else /* not __WIN32_DW */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

typedef int                     DWC_tcp_socket_t;
#define INVALID_TCP_SOCKET      (-1)

#endif /* __WIN32_DW */

typedef unsigned short          DWC_tcp_port_t;
typedef struct sockaddr_in      DWC_tcp_socket_addr_t;

extern DWC_error_code_t     init_tcp_sockets ( void );
extern DWC_error_code_t     dinit_tcp_sockets ( void );
extern DWC_error_code_t     create_tcp_socket ( DWC_tcp_socket_t *sock, DWC_bool_t nonblocking );
extern DWC_error_code_t     bind_tcp_socket ( DWC_tcp_socket_t sock, DWC_tcp_socket_addr_t* addr );
extern DWC_error_code_t     listen_tcp_socket ( DWC_tcp_socket_t sock, int backlog );
extern DWC_error_code_t     accept_tcp_socket ( DWC_tcp_socket_t sock, DWC_tcp_socket_addr_t* addr, DWC_tcp_socket_t *newsock );
extern DWC_error_code_t     connect_tcp_socket ( DWC_tcp_socket_t sock, DWC_tcp_socket_addr_t* addr, DWC_timeout_t timeout );
extern DWC_error_code_t     send_tcp_socket ( DWC_tcp_socket_t *sock, DWC_pointer_t buf, DWC_length_t *len, DWC_timeout_t timo );
extern DWC_error_code_t     recv_tcp_socket ( DWC_tcp_socket_t *sock, DWC_pointer_t buf, DWC_length_t *len, DWC_timeout_t timo );
extern DWC_error_code_t     shutdown_tcp_socket ( DWC_tcp_socket_t *sock );
extern DWC_error_code_t     close_tcp_socket ( DWC_tcp_socket_t *sock );
extern DWC_error_code_t     resolve_tcp_addr( DWC_tcp_socket_addr_t* naddr, const char* name, dwc_bool_t do_query );
extern dwc_bool_t           fill_tcp_addr( const char *host, const char *port, DWC_tcp_socket_addr_t *naddr, dwc_bool_t need_resolve );
extern dwc_bool_t           set_tcp_nodelay( DWC_tcp_socket_t sock, dwc_bool_t nodelay );     

#if defined(__cplusplus)
}
#endif 

#endif /* __DWC_TCP_H */
