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

Code before:
        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;
}

bool Win32Network::GetSocketState(NetworkSocketGroup& group, uint32 index, NetworkSocketState& state)
{
    if (index >= group.Capacity)
        return true;
    pollfd* pollptr = (pollfd*)&group.Data[index * SOCKGROUP_ITEMSIZE];
    memset(&state, 0, sizeof state);
    if (pollptr->revents & POLLERR)
        state.Error = true;
    if (pollptr->revents & POLLHUP)
        state.Disconnected = true;
    if (pollptr->revents & POLLNVAL)
        state.Invalid = true;
    if (pollptr->revents & POLLRDNORM)
        state.Readable = true;

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

Code after:
        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;
}

bool Win32Network::GetSocketState(NetworkSocketGroup& group, uint32 index, NetworkSocketState& state)
{
    if (index >= group.Capacity)
        return true;
    pollfd* pollptr = (pollfd*)&group.Data[index * SOCKGROUP_ITEMSIZE];
    memset(&state, 0, sizeof state);
    if (pollptr->revents & POLLERR)
        state.Error = true;
    if (pollptr->revents & POLLHUP)
        state.Disconnected = true;
    if (pollptr->revents & POLLNVAL)
        state.Invalid = true;
    if (pollptr->revents & POLLRDNORM)
        state.Readable = true;