uipc_socket.c (123f024b24c2b9572e279cdd76c01fd3a9d45e4a) uipc_socket.c (099a0e588cbe1bbc56a565bf57d722621b47a866)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 513 unchanged lines hidden (view full) ---

522 struct uio *uio;
523 struct mbuf *top;
524 struct mbuf *control;
525 int flags;
526 struct thread *td;
527{
528 struct mbuf **mp;
529 struct mbuf *m;
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 513 unchanged lines hidden (view full) ---

522 struct uio *uio;
523 struct mbuf *top;
524 struct mbuf *control;
525 int flags;
526 struct thread *td;
527{
528 struct mbuf **mp;
529 struct mbuf *m;
530 long space, len, resid;
531 int clen = 0, error, s, dontroute, mlen;
530 long space, len = 0, resid;
531 int clen = 0, error, s, dontroute;
532 int atomic = sosendallatonce(so) || top;
533#ifdef ZERO_COPY_SOCKETS
534 int cow_send;
535#endif /* ZERO_COPY_SOCKETS */
536
537 if (uio != NULL)
538 resid = uio->uio_resid;
539 else

--- 79 unchanged lines hidden (view full) ---

619 */
620 resid = 0;
621 if (flags & MSG_EOR)
622 top->m_flags |= M_EOR;
623 } else do {
624#ifdef ZERO_COPY_SOCKETS
625 cow_send = 0;
626#endif /* ZERO_COPY_SOCKETS */
532 int atomic = sosendallatonce(so) || top;
533#ifdef ZERO_COPY_SOCKETS
534 int cow_send;
535#endif /* ZERO_COPY_SOCKETS */
536
537 if (uio != NULL)
538 resid = uio->uio_resid;
539 else

--- 79 unchanged lines hidden (view full) ---

619 */
620 resid = 0;
621 if (flags & MSG_EOR)
622 top->m_flags |= M_EOR;
623 } else do {
624#ifdef ZERO_COPY_SOCKETS
625 cow_send = 0;
626#endif /* ZERO_COPY_SOCKETS */
627 if (top == 0) {
628 MGETHDR(m, M_TRYWAIT, MT_DATA);
629 if (m == NULL) {
630 error = ENOBUFS;
631 goto release;
632 }
633 mlen = MHLEN;
634 m->m_pkthdr.len = 0;
635 m->m_pkthdr.rcvif = (struct ifnet *)0;
636 } else {
637 MGET(m, M_TRYWAIT, MT_DATA);
638 if (m == NULL) {
639 error = ENOBUFS;
640 goto release;
641 }
642 mlen = MLEN;
643 }
644 if (resid >= MINCLSIZE) {
645#ifdef ZERO_COPY_SOCKETS
627 if (resid >= MINCLSIZE) {
628#ifdef ZERO_COPY_SOCKETS
629 if (top == NULL) {
630 MGETHDR(m, M_TRYWAIT, MT_DATA);
631 if (m == NULL) {
632 error = ENOBUFS;
633 goto release;
634 }
635 m->m_pkthdr.len = 0;
636 m->m_pkthdr.rcvif = (struct ifnet *)0;
637 } else {
638 MGET(m, M_TRYWAIT, MT_DATA);
639 if (m == NULL) {
640 error = ENOBUFS;
641 goto release;
642 }
643 }
646 if (so_zero_copy_send &&
647 resid>=PAGE_SIZE &&
648 space>=PAGE_SIZE &&
649 uio->uio_iov->iov_len>=PAGE_SIZE) {
650 so_zerocp_stats.size_ok++;
651 if (!((vm_offset_t)
652 uio->uio_iov->iov_base & PAGE_MASK)){
653 so_zerocp_stats.align_ok++;
654 cow_send = socow_setup(m, uio);
655 }
656 }
644 if (so_zero_copy_send &&
645 resid>=PAGE_SIZE &&
646 space>=PAGE_SIZE &&
647 uio->uio_iov->iov_len>=PAGE_SIZE) {
648 so_zerocp_stats.size_ok++;
649 if (!((vm_offset_t)
650 uio->uio_iov->iov_base & PAGE_MASK)){
651 so_zerocp_stats.align_ok++;
652 cow_send = socow_setup(m, uio);
653 }
654 }
657 if (!cow_send){
655 if (!cow_send) {
656 MCLGET(m, M_TRYWAIT);
657 if ((m->m_flags & M_EXT) == 0) {
658 m_free(m);
659 m = NULL;
660 } else {
661 len = min(min(MCLBYTES, resid), space);
662 }
663 } else
664 len = PAGE_SIZE;
665#else /* ZERO_COPY_SOCKETS */
666 if (top == NULL) {
667 m = m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR);
668 m->m_pkthdr.len = 0;
669 m->m_pkthdr.rcvif = (struct ifnet *)0;
670 } else
671 m = m_getcl(M_TRYWAIT, MT_DATA, 0);
672 len = min(min(MCLBYTES, resid), space);
658#endif /* ZERO_COPY_SOCKETS */
673#endif /* ZERO_COPY_SOCKETS */
659 MCLGET(m, M_TRYWAIT);
660 if ((m->m_flags & M_EXT) == 0)
661 goto nopages;
662 mlen = MCLBYTES;
663 len = min(min(mlen, resid), space);
664 } else {
674 } else {
665#ifdef ZERO_COPY_SOCKETS
666 len = PAGE_SIZE;
667 }
675 if (top == NULL) {
676 m = m_gethdr(M_TRYWAIT, MT_DATA);
677 m->m_pkthdr.len = 0;
678 m->m_pkthdr.rcvif = (struct ifnet *)0;
668
679
669 } else {
670#endif /* ZERO_COPY_SOCKETS */
671nopages:
672 len = min(min(mlen, resid), space);
673 /*
674 * For datagram protocols, leave room
675 * for protocol headers in first mbuf.
676 */
677 if (atomic && top == 0 && len < mlen)
678 MH_ALIGN(m, len);
680 len = min(min(MHLEN, resid), space);
681 /*
682 * For datagram protocols, leave room
683 * for protocol headers in first mbuf.
684 */
685 if (atomic && m && len < MHLEN)
686 MH_ALIGN(m, len);
687 } else {
688 m = m_get(M_TRYWAIT, MT_DATA);
689 len = min(min(MLEN, resid), space);
690 }
679 }
691 }
692 if (m == NULL) {
693 error = ENOBUFS;
694 goto release;
695 }
696
680 space -= len;
681#ifdef ZERO_COPY_SOCKETS
682 if (cow_send)
683 error = 0;
684 else
685#endif /* ZERO_COPY_SOCKETS */
686 error = uiomove(mtod(m, void *), (int)len, uio);
687 resid = uio->uio_resid;

--- 1231 unchanged lines hidden ---
697 space -= len;
698#ifdef ZERO_COPY_SOCKETS
699 if (cow_send)
700 error = 0;
701 else
702#endif /* ZERO_COPY_SOCKETS */
703 error = uiomove(mtod(m, void *), (int)len, uio);
704 resid = uio->uio_resid;

--- 1231 unchanged lines hidden ---