#ifndef ACL_VSTREAM_NET_INCLUDE_H
#define ACL_VSTREAM_NET_INCLUDE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "../stdlib/acl_define.h"
#include "../stdlib/acl_vstream.h"

/**
 * ĳַUNIXԼ׽֣
 * @param addr {const char*} ַ,
 *  磺127.0.0.1:80 ׽(UNIXƽ̨) 磺/tmp/test.sock Linux ƽ̨£
 *   addr ĸΪ '@' astract unix domain path.
 * @param qlen {int} еĳ
 * @param flag {unsigned} ־λμACL_INET_FLAG_XXX
 * @param io_bufsize {int} յµĿͻ׽ֵIOС
 * @param rw_timeout {int} յµĿͻ׽ֵIOдʱʱ䣬λΪ
 * @return {ACL_VSTREAM*} ָ
 */
ACL_API ACL_VSTREAM *acl_vstream_listen_ex(const char *addr, int qlen,
		unsigned flag, int io_bufsize, int rw_timeout);

/**
 * ĳַUNIXԼ׽֣
 * @param addr {const char*} ַ
 *  磺127.0.0.1:80, ׽, 磺/tmp/test.sockַΪ ip:0 ʱ
 *  ˿ںɲϵͳԶ
 * @param qlen {int} еĳ
 * @return {ACL_VSTREAM*} ָ
 */
ACL_API ACL_VSTREAM *acl_vstream_listen(const char *addr, int qlen);

/**
 * Ӽнһͻ
 * @param listen_stream {ACL_VSTREAM*} 
 * @param client_stream {ACL_VSTREAM*} ظõ ACL_VSTREAM ṹ
 *  Ϊڲһµ ACL_VSTREAM øýṹռ
 * @param ipbuf {char*} Ϊ洢ͻ˵IPַ
 * @param bsize {int}  ipbuf Ϊգʾ ipbuf ĿռС
 * @return {ACL_VSTREAM*} Ϊʾ½յĿͻ
 */
ACL_API ACL_VSTREAM *acl_vstream_accept_ex(ACL_VSTREAM *listen_stream,
		ACL_VSTREAM *client_stream, char *ipbuf, int bsize);

/**
 * Ӽнһͻ
 * @param listen_stream {ACL_VSTREAM*} 
 * @param ipbuf {char*} Ϊ洢ͻ˵IPַ
 * @param bsize {int}  ipbuf Ϊգʾ ipbuf ĿռС
 * @return {ACL_VSTREAM*} Ϊʾ½յĿͻ
 */
ACL_API ACL_VSTREAM *acl_vstream_accept(ACL_VSTREAM *listen_stream,
		char *ipbuf, int bsize);

/**
 * Զӷ
 * @param addr {const char*} ַ, һ׽ӿڷ(UNIXƽ̨),
 *  ׽ӵַ/tmp/test.sock Linux ƽ̨ĸΪ '@' ʾӱ
 *  صĳUNIX׽ӿ(Linux abstract unix domain socket)
 *  һTCPַʽΪ:
 *  remote_addr[@local_ip]|[#interface], :
 *  1. www.sina.com|80@60.28.250.199, ˼ǰ󶨱ַΪ:
 *     60.28.250.199, Զ www.sina.com  80 ˿;
 *  2.  211.150.111.12|80@192.168.1.1ʾ󶨱صַ
 *  3. 211.150.111.12|80#eth0ʾ󶨱ָ;
 *  4. OS Զ󶨱 IP ַдΪwww.sina.com|80;
 * @param block_mode {int} ӻǷӣACL_BLOCKING, ACL_NON_BLOCKING
 * @param conn_timeout {int} ӳʱʱ()
 * @param rw_timeout {int} ɹĶдʱʱ䣬λΪ
 * @param bufsize {int} ɹĻС
 * @param flags {unsigned*} ǿʱʧܵĴϢӵλ
 * @return {ACL_VSTREAM*} Ϊգʾӳɹ
 */
ACL_API ACL_VSTREAM *acl_vstream_connect2(const char *addr, int block_mode,
	int conn_timeout, int rw_timeout, int bufsize, unsigned *flags);
#define acl_vstream_connect_ex	acl_vstream_connect2

/**
 * Զӷ
 * @param addr {const char*} ַͬ
 * @param block_mode {int} ӻǷӣACL_BLOCKING, ACL_NON_BLOCKING
 * @param connect_timeout {int} ӳʱʱ()
 * @param rw_timeout {int} ɹĶдʱʱ䣬λΪ
 * @param rw_bufsize {int} ɹĻС
 * @return {ACL_VSTREAM*} Ϊգʾӳɹ
 */
ACL_API ACL_VSTREAM *acl_vstream_connect(const char *addr, int block_mode,
	int connect_timeout, int rw_timeout, int rw_bufsize);

/**
 * Զӷ
 * @param addr {const char*} ַͬ
 * @param block_mode {int} ӻǷӣACL_BLOCKING, ACL_NON_BLOCKING
 * @param connect_timeout {int} ӳʱʱ()
 * @param rw_timeout {int} ɹĶдʱʱ䣬λΪ
 * @param rw_bufsize {int} ɹĻС
 * @param flags {unsigned*} ǿʱʧܵĴϢӵλ
 * @return {ACL_VSTREAM*} Ϊգʾӳɹ
 */
ACL_API ACL_VSTREAM *acl_vstream_timed_connect(const char *addr, int block_mode,
	int connect_timeout, int rw_timeout, int rw_bufsize, unsigned *flags);

/**
 *  UDP ͨţú󶨱 UDP ַ󶨳ɹ򴴽
 * ACL_VSTREAM , û ACL_VSTREAM Ķдӿ
 * @param addr {const char*}  UDP ַʽip:portַ ip:0
 *  òϵͳԶ䱾ض˿ںţ⻹֧ UNIX ƽ̨° UNIX ׽ӿڣ
 *  UNIX ׽ӿڵĵַʽΪ{path}@udp {path} Ϊ׽ӿ·@udp Ϊ
 *  UDP ׺
 * @param rw_timeout {int} дʱʱ()
 * @param flag {unsigned} ־λ
 * @return {ACL_VSTREAM*}  NULL ʾʧ
 */
ACL_API ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout, unsigned flag);

/**
 * Ϊ UDP IO ģʽ
 * @param stream {ACL_VSTREAM*}
 */
ACL_API void acl_vstream_set_udp_io(ACL_VSTREAM *stream);

/**
 * 鲥
 * @param addr {const char*} 鲥IPַ
 * @param iface {const char*} շݰ IP ַ
 * @param port {int} շݰ Port
 * @param timeout {int} IO ʱʱ䣨룩
 * @param flag {unsigned} ־λ
 * @return {ACL_VSTREAM*}  NULL ʾʧ
 */
ACL_API ACL_VSTREAM *acl_vstream_bind_multicast(const char *addr,
	const char *iface, int port, int timeout, unsigned flag);

/**
 * 鲥 TTL ѡ (1--255)
 * @param sock {ACL_SOCKET}
 * @param ttl {int}
 * @return {int}  -1 ʾ0 ʾɹ
 */
ACL_API int acl_multicast_set_ttl(ACL_SOCKET sock, int ttl);

/**
 * 鲥󶨵ıصַ
 * @param sock {ACL_SOCKET}
 * @param addr {const char*}
 * @return {int}  0 ʾɹ-1 ʾʧ
 */
ACL_API int acl_multicast_set_if(ACL_SOCKET sock, const char *addr);

/**
 * 뿪鲥ô API ɹ󽫲ٽ鲥ݰ
 * @param sock {ACL_SOCKET}
 * @param addr {const char*} 鲥 IP
 * @param iface {const char*} 󶨵Ľ IP
 * @return {int}  0 ʾɹ-1 ʾʧ
 */
ACL_API int acl_multicast_drop(ACL_SOCKET sock, const char *addr, const char *iface);

#ifdef __cplusplus
}
#endif

#endif

