static ssize_t socket_read(struct idesc *desc, void *buff, size_t size) { int ret; struct msghdr msg; struct iovec iov; struct sock *sk = (struct sock *)desc; assert(desc); assert(desc->idesc_ops == &task_idx_ops_socket); if (sk->shutdown_flag & (SHUT_RD + 1)) { return -EPIPE; } msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_flags = 0; iov.iov_base = buff; iov.iov_len = size; ret = krecvmsg(sk, &msg, desc->idesc_flags); if (ret != 0) { return ret; } return iov.iov_len; }
/* read */ ssize_t recv(int sockfd, void *buff, size_t size, int flags) { int ret; struct msghdr msg; struct iovec iov; struct sock *sk; socket_idesc_check(sockfd, sk); if (sk->shutdown_flag & (SHUT_RD + 1)) return SET_ERRNO(EPIPE); /* TODO remove this */ if (flags != 0) { LOG_ERROR("recv", "flags are not supported"); return SET_ERRNO(EOPNOTSUPP); } msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_flags = flags; iov.iov_base = buff; iov.iov_len = size; ret = krecvmsg(sk, &msg, sk->idesc.idesc_flags); if (ret < 0) { return SET_ERRNO(-ret); } return ret; }
/* open? read */ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) { int ret; struct msghdr msg_; struct sock *sk; socket_idesc_check(sockfd, sk); if (sk->shutdown_flag & (SHUT_RD + 1)) return SET_ERRNO(EPIPE); if ((msg == NULL) || (msg->msg_iov == NULL) || (msg->msg_iovlen == 0)) { return SET_ERRNO(EINVAL); } /* TODO remove this */ if (flags != 0) { LOG_ERROR("recv", "flags are not supported"); return SET_ERRNO(EOPNOTSUPP); } memcpy(&msg_, msg, sizeof msg_); msg_.msg_flags = flags; ret = krecvmsg(sk, &msg_, sk->idesc.idesc_flags); if (ret < 0) { return SET_ERRNO(-ret); } msg->msg_name = msg_.msg_name; msg->msg_namelen = msg_.msg_namelen; msg->msg_flags = msg_.msg_flags; return ret; }