driconf: add force_integer_tex_nearest option
[mesa.git] / src / util / os_socket.c
1 /*
2 * Copyright 2019 Intel Corporation
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include <errno.h>
7
8 #include "os_socket.h"
9
10 #if defined(__linux__)
11
12 #include <fcntl.h>
13 #include <poll.h>
14 #include <stddef.h>
15 #include <string.h>
16 #include <sys/socket.h>
17 #include <sys/un.h>
18 #include <unistd.h>
19
20 int
21 os_socket_listen_abstract(const char *path, int count)
22 {
23 int s = socket(AF_UNIX, SOCK_STREAM, 0);
24 if (s < 0)
25 return -1;
26
27 struct sockaddr_un addr;
28 memset(&addr, 0, sizeof(addr));
29 addr.sun_family = AF_UNIX;
30 strncpy(addr.sun_path + 1, path, sizeof(addr.sun_path) - 2);
31
32 /* Create an abstract socket */
33 int ret = bind(s, (struct sockaddr*)&addr,
34 offsetof(struct sockaddr_un, sun_path) +
35 strlen(path) + 1);
36 if (ret < 0)
37 return -1;
38
39 listen(s, count);
40
41 return s;
42 }
43
44 int
45 os_socket_accept(int s)
46 {
47 return accept(s, NULL, NULL);
48 }
49
50 ssize_t
51 os_socket_recv(int socket, void *buffer, size_t length, int flags)
52 {
53 return recv(socket, buffer, length, flags);
54 }
55
56 ssize_t
57 os_socket_send(int socket, const void *buffer, size_t length, int flags)
58 {
59 return send(socket, buffer, length, flags);
60 }
61
62 void
63 os_socket_block(int s, bool block)
64 {
65 int old = fcntl(s, F_GETFL, 0);
66 if (old == -1)
67 return;
68
69 /* TODO obey block */
70 if (block)
71 fcntl(s, F_SETFL, old & ~O_NONBLOCK);
72 else
73 fcntl(s, F_SETFL, old | O_NONBLOCK);
74 }
75
76 void
77 os_socket_close(int s)
78 {
79 close(s);
80 }
81
82 #else
83
84 int
85 os_socket_listen_abstract(const char *path, int count)
86 {
87 errno = -ENOSYS;
88 return -1;
89 }
90
91 int
92 os_socket_accept(int s)
93 {
94 errno = -ENOSYS;
95 return -1;
96 }
97
98 ssize_t
99 os_socket_recv(int socket, void *buffer, size_t length, int flags)
100 {
101 errno = -ENOSYS;
102 return -1;
103 }
104
105 ssize_t
106 os_socket_send(int socket, const void *buffer, size_t length, int flags)
107 {
108 errno = -ENOSYS;
109 return -1;
110 }
111
112 void
113 os_socket_block(int s, bool block)
114 {
115 }
116
117 void
118 os_socket_close(int s)
119 {
120 }
121
122 #endif