diff options
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index ac7f2aacc77b..4a8f37f48764 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -607,23 +607,24 @@ exit: | |||
607 | static int send_stream(struct kiocb *iocb, struct socket *sock, | 607 | static int send_stream(struct kiocb *iocb, struct socket *sock, |
608 | struct msghdr *m, size_t total_len) | 608 | struct msghdr *m, size_t total_len) |
609 | { | 609 | { |
610 | struct tipc_port *tport; | ||
610 | struct msghdr my_msg; | 611 | struct msghdr my_msg; |
611 | struct iovec my_iov; | 612 | struct iovec my_iov; |
612 | struct iovec *curr_iov; | 613 | struct iovec *curr_iov; |
613 | int curr_iovlen; | 614 | int curr_iovlen; |
614 | char __user *curr_start; | 615 | char __user *curr_start; |
616 | u32 hdr_size; | ||
615 | int curr_left; | 617 | int curr_left; |
616 | int bytes_to_send; | 618 | int bytes_to_send; |
617 | int bytes_sent; | 619 | int bytes_sent; |
618 | int res; | 620 | int res; |
619 | 621 | ||
620 | if (likely(total_len <= TIPC_MAX_USER_MSG_SIZE)) | 622 | /* Handle special cases where there is no connection */ |
621 | return send_packet(iocb, sock, m, total_len); | ||
622 | |||
623 | /* Can only send large data streams if already connected */ | ||
624 | 623 | ||
625 | if (unlikely(sock->state != SS_CONNECTED)) { | 624 | if (unlikely(sock->state != SS_CONNECTED)) { |
626 | if (sock->state == SS_DISCONNECTING) | 625 | if (sock->state == SS_UNCONNECTED) |
626 | return send_packet(iocb, sock, m, total_len); | ||
627 | else if (sock->state == SS_DISCONNECTING) | ||
627 | return -EPIPE; | 628 | return -EPIPE; |
628 | else | 629 | else |
629 | return -ENOTCONN; | 630 | return -ENOTCONN; |
@@ -648,17 +649,25 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
648 | my_msg.msg_name = NULL; | 649 | my_msg.msg_name = NULL; |
649 | bytes_sent = 0; | 650 | bytes_sent = 0; |
650 | 651 | ||
652 | tport = tipc_sk(sock->sk)->p; | ||
653 | hdr_size = msg_hdr_sz(&tport->phdr); | ||
654 | |||
651 | while (curr_iovlen--) { | 655 | while (curr_iovlen--) { |
652 | curr_start = curr_iov->iov_base; | 656 | curr_start = curr_iov->iov_base; |
653 | curr_left = curr_iov->iov_len; | 657 | curr_left = curr_iov->iov_len; |
654 | 658 | ||
655 | while (curr_left) { | 659 | while (curr_left) { |
656 | bytes_to_send = (curr_left < TIPC_MAX_USER_MSG_SIZE) | 660 | bytes_to_send = tport->max_pkt - hdr_size; |
657 | ? curr_left : TIPC_MAX_USER_MSG_SIZE; | 661 | if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) |
662 | bytes_to_send = TIPC_MAX_USER_MSG_SIZE; | ||
663 | if (curr_left < bytes_to_send) | ||
664 | bytes_to_send = curr_left; | ||
658 | my_iov.iov_base = curr_start; | 665 | my_iov.iov_base = curr_start; |
659 | my_iov.iov_len = bytes_to_send; | 666 | my_iov.iov_len = bytes_to_send; |
660 | if ((res = send_packet(iocb, sock, &my_msg, 0)) < 0) { | 667 | if ((res = send_packet(iocb, sock, &my_msg, 0)) < 0) { |
661 | return bytes_sent ? bytes_sent : res; | 668 | if (bytes_sent != 0) |
669 | res = bytes_sent; | ||
670 | return res; | ||
662 | } | 671 | } |
663 | curr_left -= bytes_to_send; | 672 | curr_left -= bytes_to_send; |
664 | curr_start += bytes_to_send; | 673 | curr_start += bytes_to_send; |