少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "il2cpp-config.h"
 
#if (IL2CPP_TARGET_POSIX || IL2CPP_SUPPORT_SOCKETS_POSIX_API) && !IL2CPP_TINY_WITHOUT_DEBUGGER
 
#if IL2CPP_TARGET_SWITCH
#include <errno.h>
#else
#include <sys/errno.h>
#endif
 
#include "os/Posix/PosixHelpers.h"
 
namespace il2cpp
{
namespace os
{
namespace posix
{
    int Poll(pollfd* handles, int numHandles, int timeout)
    {
        int32_t ret = 0;
        time_t start = time(NULL);
 
        do
        {
            ret = poll(handles, numHandles, timeout);
 
            if (timeout > 0 && ret < 0)
            {
                const int32_t err = errno;
                const int32_t sec = time(NULL) - start;
 
                timeout -= sec * 1000;
 
                if (timeout < 0)
                    timeout = 0;
 
                errno = err;
            }
        }
#if IL2CPP_TARGET_LINUX
        while (ret == -1 && (errno == EINTR || errno == EAGAIN));
#else
        while (ret == -1 && errno == EINTR);
#endif
 
#if IL2CPP_TARGET_LINUX
        // On Linux, socket will report POLLERR if the other end has been closed, in addition to normal POLLHUP
        // From man page:
        // POLLERR
        //   Error condition(only returned in revents; ignored in events).
        //   This bit is also set for a file descriptor referring to the
        //   write end of a pipe when the read end has been closed.
        //
        // Mac and Windows doesn't do it, so we zero out that bit if POLLHUP is set on Linux to get consistent behaviour
        for (int i = 0; i < numHandles; i++)
        {
            if ((handles[i].revents & POLLERR) && (handles[i].revents & POLLHUP))
                handles[i].revents &= ~POLLERR & handles[i].events;
        }
#endif
 
        return ret;
    }
}
}
}
 
#endif // IL2CPP_TARGET_POSIX