RemoteInspectorSocket.h [plain text]
#pragma once
#if ENABLE(REMOTE_INSPECTOR)
#include <array>
#include <wtf/Optional.h>
#include <wtf/Vector.h>
#if OS(WINDOWS)
#include <winsock2.h>
#else
#include <poll.h>
#endif
namespace Inspector {
using ConnectionID = uint32_t;
#if OS(WINDOWS)
using PlatformSocketType = SOCKET;
using PollingDescriptor = WSAPOLLFD;
constexpr PlatformSocketType INVALID_SOCKET_VALUE = INVALID_SOCKET;
#else
using PlatformSocketType = int;
using PollingDescriptor = struct pollfd;
constexpr PlatformSocketType INVALID_SOCKET_VALUE = -1;
#endif
namespace Socket {
enum class Domain {
Local,
Network,
};
void init();
Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort);
Optional<PlatformSocketType> listen(const char* address, uint16_t port);
Optional<PlatformSocketType> accept(PlatformSocketType);
Optional<std::array<PlatformSocketType, 2>> createPair();
bool setup(PlatformSocketType);
bool isValid(PlatformSocketType);
bool isListening(PlatformSocketType);
Optional<uint16_t> getPort(PlatformSocketType);
Optional<size_t> read(PlatformSocketType, void* buffer, int bufferSize);
Optional<size_t> write(PlatformSocketType, const void* data, int size);
void close(PlatformSocketType&);
PollingDescriptor preparePolling(PlatformSocketType);
bool poll(Vector<PollingDescriptor>&, int timeout);
bool isReadable(const PollingDescriptor&);
bool isWritable(const PollingDescriptor&);
void markWaitingWritable(PollingDescriptor&);
void clearWaitingWritable(PollingDescriptor&);
constexpr size_t BufferSize = 65536;
}
}
#endif // ENABLE(REMOTE_INSPECTOR)