11#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
15#include <sys/socket.h>
21#define OFFSET_OF(type, field) \
22 (reinterpret_cast<intptr_t>( \
23 &(reinterpret_cast<type*>(kOffsetOfPtr)->field)) - \
27 struct sockaddr_un
addr;
35 "Usage: abstract_socket_test <address>\n\n"
36 "<address> should be an abstract UNIX socket address like @hidden\n");
40 socket_path =
argv[1];
41 if (socket_path[0] !=
'@') {
43 "The first argument should be an abstract socket "
44 "address and start with '@'\n");
48 if ((server_socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
49 perror(
"socket error");
54 addr.sun_family = AF_UNIX;
55 addr.sun_path[0] =
'\0';
56 strncpy(
addr.sun_path + 1, socket_path + 1,
sizeof(
addr.sun_path) - 2);
59 OFFSET_OF(
struct sockaddr_un, sun_path) + strlen(socket_path);
60 if (bind(server_socket, (
struct sockaddr*)&
addr, address_length) == -1) {
65 if (listen(server_socket, 5) == -1) {
66 perror(
"listen error");
71 if ((client_socket = accept(server_socket,
nullptr,
nullptr)) == -1) {
72 perror(
"accept error");
77 while ((read_count =
read(client_socket, buf,
sizeof(buf))) > 0) {
79 while (write_count < read_count) {
81 if ((
w =
write(client_socket, buf, read_count)) < 0) {
88 if (read_count == -1) {
static bool read(SkStream *stream, void *buffer, size_t amount)
const intptr_t kOffsetOfPtr
void write(SkWStream *wStream, const T &text)
#define OFFSET_OF(type, field)