#ifndef   __SOCKET5_20050630_H__
#define   __SOCKET5_20050630_H__

#ifndef __BORLANDC__
        //this DJGPP
        #include <sys\types.h>
#else

#define		FD_SETSIZE		64
typedef struct fd_set
{
		u_int   fd_count;               //有多少个SOCKET需要SET
		SOCKET  fd_array[FD_SETSIZE];
} fd_set;
typedef struct fd_set FD_SET;
typedef struct fd_set *PFD_SET;
typedef struct fd_set FAR *LPFD_SET;

//从套接字集合中删除其中的一个描述符
#define FD_CLR(fd, set) do { \
    u_int __i; \
    for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
        if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
            while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
                ((fd_set FAR *)(set))->fd_array[__i] = \
                    ((fd_set FAR *)(set))->fd_array[__i+1]; \
				__i++; \
            } \
            ((fd_set FAR *)(set))->fd_count--; \
            break; \
        } \
    } \
} while(0)

//检索指定的套接字是否在套接字集合中
#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))

//将指定的套接字加入到套接字集合中
#define FD_SET(fd, set) do { \
    if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
        ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
} while(0)

//将套接字集合设成0个元素
#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)

typedef struct timeval TIMEVAL;
typedef struct timeval *PTIMEVAL;
typedef struct timeval FAR *LPTIMEVAL;


#endif


#endif