crafcat7 commented on code in PR #15597: URL: https://github.com/apache/nuttx/pull/15597#discussion_r1921103120
########## net/tcp/tcp_recvfrom.c: ########## @@ -843,10 +843,71 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR struct msghdr *msg, } tcp_notify_recvcpu(conn); + tcp_recvfrom_uninitialize(&state); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: psock_tcp_recvfrom + * + * Description: + * Perform the recvfrom operation for a TCP/IP SOCK_STREAM + * + * Input Parameters: + * psock Pointer to the socket structure for the SOCK_DRAM socket + * msg Receive info and buffer for receive data + * flags Receive flags + * + * Returned Value: + * On success, returns the number of characters received. On error, + * -errno is returned (see recvfrom for list of errnos). + * + * Assumptions: + * + ****************************************************************************/ + +ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR struct msghdr *msg, + int flags) +{ + FAR struct sockaddr *from = msg->msg_name; + FAR socklen_t *fromlen = &msg->msg_namelen; + FAR struct tcp_conn_s *conn; + ssize_t nrecv = 0; + ssize_t ret = 0; + int i; + + net_lock(); + + conn = psock->s_conn; + for (i = 0; i < msg->msg_iovlen; i++) + { + FAR void *buf = msg->msg_iov[i].iov_base; + size_t len = msg->msg_iov[i].iov_len; + + ret = tcp_recvfrom_one(conn, buf, len, from, fromlen, flags); + + /* User has not set MSG_WAITALL: If the first buffer is full + * when received for the first time, then check the next buffer, + * otherwise return the received data. + * User sets MSG_WAITALL: Ensure that each iov is filled before + * returning + */ + + if (ret < 0 || + (!(flags & MSG_WAITALL) && ret < msg->msg_iov[i].iov_len)) Review Comment: The current design expectation is: when receiving multiple segments of iov, if an error occurs in one segment, an error code is returned to inform the caller. If we are not in MSG_WAITALL, then as long as there is one recv, we can directly return ret. Otherwise, when we ensure that ret >= 0, we will return nrecv. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org