Lines Matching refs:uctx
98 struct uds_ctx *uctx; in uds_common_setup() local
101 uctx = malloc(sizeof(*uctx)); in uds_common_setup()
102 if (uctx == NULL) in uds_common_setup()
106 error = uds_addr(addr, &uctx->uc_sun); in uds_common_setup()
108 free(uctx); in uds_common_setup()
112 uctx->uc_fd = socket(AF_UNIX, SOCK_STREAM, 0); in uds_common_setup()
113 if (uctx->uc_fd == -1) { in uds_common_setup()
115 free(uctx); in uds_common_setup()
119 uctx->uc_side = side; in uds_common_setup()
120 uctx->uc_owner = 0; in uds_common_setup()
121 uctx->uc_magic = UDS_CTX_MAGIC; in uds_common_setup()
122 *uctxp = uctx; in uds_common_setup()
130 struct uds_ctx *uctx; in uds_connect() local
136 error = uds_common_setup(dstaddr, UDS_SIDE_CLIENT, &uctx); in uds_connect()
142 if (connect(uctx->uc_fd, (struct sockaddr *)&uctx->uc_sun, in uds_connect()
143 sizeof(uctx->uc_sun)) == -1) { in uds_connect()
145 uds_close(uctx); in uds_connect()
149 *ctxp = uctx; in uds_connect()
157 struct uds_ctx *uctx = ctx; in uds_connect_wait() local
159 PJDLOG_ASSERT(uctx != NULL); in uds_connect_wait()
160 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_connect_wait()
161 PJDLOG_ASSERT(uctx->uc_side == UDS_SIDE_CLIENT); in uds_connect_wait()
162 PJDLOG_ASSERT(uctx->uc_fd >= 0); in uds_connect_wait()
171 struct uds_ctx *uctx; in uds_server() local
174 error = uds_common_setup(addr, UDS_SIDE_SERVER_LISTEN, &uctx); in uds_server()
178 (void)unlink(uctx->uc_sun.sun_path); in uds_server()
179 if (bind(uctx->uc_fd, (struct sockaddr *)&uctx->uc_sun, in uds_server()
180 sizeof(uctx->uc_sun)) == -1) { in uds_server()
182 uds_close(uctx); in uds_server()
185 uctx->uc_owner = getpid(); in uds_server()
186 if (listen(uctx->uc_fd, 8) == -1) { in uds_server()
188 uds_close(uctx); in uds_server()
192 *ctxp = uctx; in uds_server()
200 struct uds_ctx *uctx = ctx; in uds_accept() local
205 PJDLOG_ASSERT(uctx != NULL); in uds_accept()
206 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_accept()
207 PJDLOG_ASSERT(uctx->uc_side == UDS_SIDE_SERVER_LISTEN); in uds_accept()
208 PJDLOG_ASSERT(uctx->uc_fd >= 0); in uds_accept()
215 newuctx->uc_fd = accept(uctx->uc_fd, in uds_accept()
233 struct uds_ctx *uctx = ctx; in uds_send() local
235 PJDLOG_ASSERT(uctx != NULL); in uds_send()
236 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_send()
237 PJDLOG_ASSERT(uctx->uc_fd >= 0); in uds_send()
239 return (proto_common_send(uctx->uc_fd, data, size, fd)); in uds_send()
245 struct uds_ctx *uctx = ctx; in uds_recv() local
247 PJDLOG_ASSERT(uctx != NULL); in uds_recv()
248 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_recv()
249 PJDLOG_ASSERT(uctx->uc_fd >= 0); in uds_recv()
251 return (proto_common_recv(uctx->uc_fd, data, size, fdp)); in uds_recv()
257 const struct uds_ctx *uctx = ctx; in uds_descriptor() local
259 PJDLOG_ASSERT(uctx != NULL); in uds_descriptor()
260 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_descriptor()
262 return (uctx->uc_fd); in uds_descriptor()
268 const struct uds_ctx *uctx = ctx; in uds_local_address() local
272 PJDLOG_ASSERT(uctx != NULL); in uds_local_address()
273 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_local_address()
277 if (getsockname(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { in uds_local_address()
292 const struct uds_ctx *uctx = ctx; in uds_remote_address() local
296 PJDLOG_ASSERT(uctx != NULL); in uds_remote_address()
297 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_remote_address()
301 if (getpeername(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { in uds_remote_address()
316 struct uds_ctx *uctx = ctx; in uds_close() local
318 PJDLOG_ASSERT(uctx != NULL); in uds_close()
319 PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); in uds_close()
321 if (uctx->uc_fd >= 0) in uds_close()
322 close(uctx->uc_fd); in uds_close()
327 if (uctx->uc_side == UDS_SIDE_SERVER_LISTEN && in uds_close()
328 uctx->uc_owner == getpid()) { in uds_close()
329 PJDLOG_ASSERT(uctx->uc_sun.sun_path[0] != '\0'); in uds_close()
330 if (unlink(uctx->uc_sun.sun_path) == -1) { in uds_close()
333 uctx->uc_sun.sun_path); in uds_close()
336 uctx->uc_owner = 0; in uds_close()
337 uctx->uc_magic = 0; in uds_close()
338 free(uctx); in uds_close()