Lines Matching refs:fd
106 static void *fd_to_handle_ptr(int fd) in fd_to_handle_ptr() argument
110 assert(fd >= 0); in fd_to_handle_ptr()
111 ptr = fd + 1; in fd_to_handle_ptr()
121 static int sock_handle_get(uint32_t instance_id, int fd) in sock_handle_get() argument
137 handle = handle_get(&si->db, fd_to_handle_ptr(fd)); in sock_handle_get()
145 int fd = -1; in sock_handle_to_fd() local
151 fd = handle_ptr_to_fd(handle_lookup(&si->db, handle)); in sock_handle_to_fd()
153 return fd; in sock_handle_to_fd()
172 static int fd_flags_add(int fd, int flags) in fd_flags_add() argument
176 val = fcntl(fd, F_GETFD, 0); in fd_flags_add()
182 return fcntl(fd, F_SETFL, val); in fd_flags_add()
191 int fd = -1; in sock_connect() local
224 fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); in sock_connect()
225 if (fd == -1) { in sock_connect()
233 if (connect(fd, res->ai_addr, res->ai_addrlen)) { in sock_connect()
239 close(fd); in sock_connect()
240 fd = -1; in sock_connect()
244 if (fd_flags_add(fd, O_NONBLOCK)) { in sock_connect()
245 close(fd); in sock_connect()
246 fd = -1; in sock_connect()
256 *ret_fd = fd; in sock_connect()
265 int fd = 0; in tee_socket_open() local
288 res = sock_connect(ip_vers, protocol, server, port, &fd); in tee_socket_open()
292 handle = sock_handle_get(instance_id, fd); in tee_socket_open()
294 close(fd); in tee_socket_open()
307 int fd = 0; in tee_socket_close() local
315 fd = sock_handle_to_fd(instance_id, handle); in tee_socket_close()
316 if (fd < 0) in tee_socket_close()
319 if (close(fd)) { in tee_socket_close()
320 EMSG("tee_socket_close: close(%d): %s", fd, strerror(errno)); in tee_socket_close()
329 int fd = handle_ptr_to_fd(ptr); in sock_close_cb() local
331 if (close(fd)) in sock_close_cb()
333 si->id, handle, fd, strerror(errno)); in sock_close_cb()
445 static TEEC_Result write_with_timeout(int fd, const void *buf, size_t *blen, in write_with_timeout() argument
449 struct pollfd pfd = { .fd = fd, .events = POLLOUT }; in write_with_timeout()
456 r = write(fd, buf, *blen); in write_with_timeout()
471 int fd = 0; in tee_socket_send() local
484 fd = sock_handle_to_fd(instance_id, handle); in tee_socket_send()
485 if (fd < 0) in tee_socket_send()
490 res = write_with_timeout(fd, buf, &bytes, params[2].a); in tee_socket_send()
496 static ssize_t recv_with_out_flags(int fd, void *buf, size_t len, int inflags, in recv_with_out_flags() argument
505 r = recvmsg(fd, &msg, inflags); in recv_with_out_flags()
521 static TEEC_Result read_with_timeout(int fd, void *buf, size_t *blen, in read_with_timeout() argument
525 struct pollfd pfd = { .fd = fd, .events = POLLIN }; in read_with_timeout()
533 if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &socktype, &l)) in read_with_timeout()
549 r = recv_with_out_flags(fd, b, SUPP_MAX_PEEK_LEN, in read_with_timeout()
571 r = recv_with_out_flags(fd, buf, *blen, MSG_DONTWAIT, &out_flags); in read_with_timeout()
610 int fd = 0; in tee_socket_recv() local
623 fd = sock_handle_to_fd(instance_id, handle); in tee_socket_recv()
624 if (fd < 0) in tee_socket_recv()
630 res = read_with_timeout(fd, buf, &bytes, params[2].a); in tee_socket_recv()
637 static TEEC_Result tee_socket_ioctl_tcp(int fd, uint32_t command, in tee_socket_ioctl_tcp() argument
642 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, buf, *blen)) in tee_socket_ioctl_tcp()
646 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, buf, *blen)) in tee_socket_ioctl_tcp()
706 static TEEC_Result udp_changeaddr(int fd, int family, const char *server, in udp_changeaddr() argument
724 if (connect(fd, res->ai_addr, res->ai_addrlen)) { in udp_changeaddr()
739 static TEEC_Result tee_socket_ioctl_udp(int fd, uint32_t command, in tee_socket_ioctl_udp() argument
750 if (getpeername(fd, sa, &len)) in tee_socket_ioctl_udp()
762 return udp_changeaddr(fd, sa->sa_family, buf, port); in tee_socket_ioctl_udp()
770 if (connect(fd, sa, len)) in tee_socket_ioctl_udp()
783 int fd = 0; in tee_socket_ioctl() local
800 fd = sock_handle_to_fd(instance_id, handle); in tee_socket_ioctl()
801 if (fd < 0) in tee_socket_ioctl()
805 if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &socktype, &l)) in tee_socket_ioctl()
813 res = tee_socket_ioctl_tcp(fd, command, buf, &sz); in tee_socket_ioctl()
818 res = tee_socket_ioctl_udp(fd, command, buf, &sz); in tee_socket_ioctl()