Repository: FlaxEngine/FlaxEngine
File: Source/Engine/Platform/Win32/Win32Network.cpp (C++)

Code before:
    if (entry.revents & POLLRDNORM)
        return true;
    return false;
}

bool Win32Network::IsWriteable(NetworkSocket& socket)
{
    pollfd entry;
    entry.fd = *(SOCKET*)socket.Data;
    entry.events = POLLWRNORM;
    if (WSAPoll(&entry, 1, 0) == SOCKET_ERROR)
    {
        int32 error = WSAGetLastError();
        if (error == WSAEWOULDBLOCK)
            return false;
        LOG(Error, "Unable to poll socket! Socket : {0} Error : {1}", *(SOCKET*)socket.Data, GetErrorMessage(error));
        return false;
    }
    if (entry.revents & POLLWRNORM)
        return true;
    return false;
}

bool Win32Network::CreateSocketGroup(uint32 capacity, NetworkSocketGroup& group)
{
    if (!(group.Data = (byte*)malloc(capacity * SOCKGROUP_ITEMSIZE)))
    {
        LOG(Error, "Unable to malloc NetworkSocketGroup::Data ! Size : {0}", capacity * SOCKGROUP_ITEMSIZE);
        return true;
    }
    group.Capacity = capacity;
    for(int i = 0; i < (int)group.Capacity; i++)
        ((pollfd*)&group.Data[i * SOCKGROUP_ITEMSIZE])->fd = -1;
    
    return false;
}

bool Win32Network::DestroySocketGroup(NetworkSocketGroup& group)
{
    if (!group.Data)
        return true;
    free(group.Data);
    return false;
}

int32 Win32Network::Poll(NetworkSocketGroup& group)
{
    int32 pollret = WSAPoll((pollfd*)group.Data, group.Count, 0);
    if (pollret == SOCKET_ERROR)
        LOG(Error, "Unable to poll socket group! Error : {0}", GetLastErrorMessage());
    return pollret;

Review comment (suggestion):
Use `Platform::Allocate()` to unify memory allocations in the engine (with profiling).

Code after:
    if (entry.revents & POLLRDNORM)
        return true;
    return false;
}

bool Win32Network::IsWriteable(NetworkSocket& socket)
{
    pollfd entry;
    entry.fd = *(SOCKET*)socket.Data;
    entry.events = POLLWRNORM;
    if (WSAPoll(&entry, 1, 0) == SOCKET_ERROR)
    {
        int32 error = WSAGetLastError();
        if (error == WSAEWOULDBLOCK)
            return false;
        LOG(Error, "Unable to poll socket! Socket : {0} Error : {1}", *(SOCKET*)socket.Data, GetErrorMessage(error));
        return false;
    }
    if (entry.revents & POLLWRNORM)
        return true;
    return false;
}

bool Win32Network::CreateSocketGroup(uint32 capacity, NetworkSocketGroup& group)
{
    if (!(group.Data = (byte*)Platform::Allocate(capacity * SOCKGROUP_ITEMSIZE, 16)))
    {
        LOG(Error, "Unable to malloc NetworkSocketGroup::Data ! Size : {0}", capacity * SOCKGROUP_ITEMSIZE);
        return true;
    }
    group.Capacity = capacity;
    for(int i = 0; i < (int)group.Capacity; i++)
        ((pollfd*)&group.Data[i * SOCKGROUP_ITEMSIZE])->fd = -1;
    
    return false;
}

bool Win32Network::DestroySocketGroup(NetworkSocketGroup& group)
{
    if (!group.Data)
        return true;
    Platform::Free(group.Data);
    return false;
}

int32 Win32Network::Poll(NetworkSocketGroup& group)
{
    int32 pollret = WSAPoll((pollfd*)group.Data, group.Count, 0);
    if (pollret == SOCKET_ERROR)
        LOG(Error, "Unable to poll socket group! Error : {0}", GetLastErrorMessage());
    return pollret;