SocketImpl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #if IL2CPP_USE_GENERIC_SOCKET_IMPL
  3. #include <string>
  4. #include <vector>
  5. #include <stdint.h>
  6. #include "os/Socket.h"
  7. #include "os/ErrorCodes.h"
  8. #include "os/WaitStatus.h"
  9. #include "utils/NonCopyable.h"
  10. namespace il2cpp
  11. {
  12. namespace os
  13. {
  14. class SocketImpl : public il2cpp::utils::NonCopyable
  15. {
  16. public:
  17. typedef int32_t SocketDescriptor;
  18. SocketImpl(ThreadStatusCallback thread_status_callback);
  19. ~SocketImpl();
  20. inline SocketDescriptor GetDescriptor()
  21. {
  22. return -1;
  23. }
  24. ErrorCode GetLastError() const;
  25. WaitStatus Create(SocketDescriptor fd, int32_t family, int32_t type, int32_t protocol);
  26. WaitStatus Create(AddressFamily family, SocketType type, ProtocolType protocol);
  27. WaitStatus Close();
  28. bool IsClosed()
  29. {
  30. return true;
  31. }
  32. WaitStatus SetBlocking(bool blocking);
  33. WaitStatus Listen(int32_t blacklog);
  34. WaitStatus Bind(const char *path);
  35. WaitStatus Bind(const char *address, uint16_t port);
  36. WaitStatus Bind(uint32_t address, uint16_t port);
  37. WaitStatus Bind(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port);
  38. WaitStatus Connect(const char *path);
  39. WaitStatus Connect(uint32_t address, uint16_t port);
  40. WaitStatus Connect(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port);
  41. WaitStatus Disconnect(bool reuse);
  42. WaitStatus Shutdown(int32_t how);
  43. WaitStatus GetLocalEndPointInfo(EndPointInfo &info);
  44. WaitStatus GetRemoteEndPointInfo(EndPointInfo &info);
  45. WaitStatus Receive(const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
  46. WaitStatus Send(const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
  47. WaitStatus SendArray(WSABuf *wsabufs, int32_t count, int32_t *sent, SocketFlags c_flags);
  48. WaitStatus ReceiveArray(WSABuf *wsabufs, int32_t count, int32_t *len, SocketFlags c_flags);
  49. WaitStatus SendTo(uint32_t address, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
  50. WaitStatus SendTo(const char *path, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
  51. WaitStatus SendTo(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len);
  52. WaitStatus RecvFrom(uint32_t address, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
  53. WaitStatus RecvFrom(const char *path, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
  54. WaitStatus RecvFrom(uint8_t address[ipv6AddressSize], uint32_t scope, uint16_t port, const uint8_t *data, int32_t count, os::SocketFlags flags, int32_t *len, os::EndPointInfo &ep);
  55. WaitStatus Accept(os::Socket **socket);
  56. WaitStatus Available(int32_t *amount);
  57. WaitStatus Ioctl(int32_t command, const uint8_t *in_data, int32_t in_len, uint8_t *out_data, int32_t out_len, int32_t *written);
  58. WaitStatus GetSocketOption(SocketOptionLevel level, SocketOptionName name, uint8_t *buffer, int32_t *length);
  59. WaitStatus GetSocketOptionFull(SocketOptionLevel level, SocketOptionName name, int32_t *first, int32_t *second);
  60. WaitStatus SetSocketOption(SocketOptionLevel level, SocketOptionName name, int32_t value);
  61. WaitStatus SetSocketOptionLinger(SocketOptionLevel level, SocketOptionName name, bool enabled, int32_t seconds);
  62. WaitStatus SetSocketOptionArray(SocketOptionLevel level, SocketOptionName name, const uint8_t *buffer, int32_t length);
  63. WaitStatus SetSocketOptionMembership(SocketOptionLevel level, SocketOptionName name, uint32_t group_address, uint32_t local_address);
  64. #if IL2CPP_SUPPORT_IPV6
  65. WaitStatus SetSocketOptionMembership(SocketOptionLevel level, SocketOptionName name, IPv6Address ipv6, uint64_t interfaceOffset);
  66. #endif
  67. WaitStatus SendFile(const char *filename, TransmitFileBuffers *buffers, TransmitFileOptions options);
  68. static WaitStatus Poll(std::vector<PollRequest> &requests, int32_t count, int32_t timeout, int32_t *result, int32_t *error);
  69. static WaitStatus Poll(std::vector<PollRequest> &requests, int32_t timeout, int32_t *result, int32_t *error);
  70. static WaitStatus Poll(PollRequest& request, int32_t timeout, int32_t *result, int32_t *error);
  71. static WaitStatus GetHostName(std::string &name);
  72. static WaitStatus GetHostByName(const std::string &host, std::string &name, std::vector<std::string> &aliases, std::vector<std::string> &addr_list);
  73. static WaitStatus GetHostByAddr(const std::string &address, std::string &name, std::vector<std::string> &aliases, std::vector<std::string> &addr_list);
  74. static void Startup();
  75. static void Cleanup();
  76. };
  77. }
  78. }
  79. #endif