Previous topicNext topic
Help > XEngine_Core > XEngine_ManagePool > SocketPool >
ManagePool_Socket_Create

函数

ManagePool_Socket_Create

功能

创建一个连接池

语法

BOOL ManagePool_Socket_Create(XNETHANDLE *pxhPool, DWORD dwSocketNumber, DWORD dwSocket = NETENGINE_MANAGEPOOL_SOCKET_IN_TYPE_TCPV4)

参数

 参数.一:pxhPool
  In/Out:In/Out
  类型:连接池句柄指针
  可空:N
  意思:导出一个新分配的连接池句柄
 参数.二:dwSocketNumber
  In/Out:In
  类型:双字
  可空:N
  意思:要创建的套接字个数
 参数.三:dwSocket
  In/Out:In
  类型:双字
  可空:Y
  意思:套接字属性,默认给你设置为TCP V4版本

返回值

类型:逻辑型
意思:是否成功

备注

使用了我们的连接池后,套接字全部交由我们来管理,你不需要并且不能管理套接字

示例

void SocketPool_Test()
{
    XNETHANDLE xhPool = 0;
    if (!ManagePool_Socket_Create(&xhPool, 100))
    {
        printf("ManagePool_Socket_Create!@\n");
        return;
    }
    SOCKET hSocket = INVALID_SOCKET;
    if (!ManagePool_Socket_GetIdleSocket(xhPool, &hSocket))
    {
        printf("ManagePool_Socket_GetIdleSocket!@\n");
        return;
    }
    sockaddr_in st_SockProxy;

    st_SockProxy.sin_addr.s_addr = inet_addr("192.168.1.4");
    st_SockProxy.sin_port = htons(5002);
    st_SockProxy.sin_family = AF_INET;

    if (SOCKET_ERROR == connect(hSocket, (sockaddr*)&st_SockProxy, sizeof(st_SockProxy)))
    {
    }
    send(hSocket, "hello", 5, 0);
    if (!ManagePool_Socket_RetIdleSocket(xhPool, hSocket))
    {
        printf("ManagePool_Socket_GetIdleSocket!@\n");
        return;
    }
    ManagePool_Socket_Destroy(xhPool);
}