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
--- 20 unchanged lines hidden (view full) ---
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 121307 2003-10-21 18:28:36Z silby $");
38
39#include "opt_inet.h"
40#include "opt_mac.h"
41#include "opt_zero.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/fcntl.h>
--- 837 unchanged lines hidden (view full) ---
883 goto release;
884 }
885 if (uio->uio_resid == 0)
886 goto release;
887 if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
888 error = EWOULDBLOCK;
889 goto release;
890 }
891 sbunlock(&so->so_rcv);
892 error = sbwait(&so->so_rcv);
893 splx(s);
894 if (error)
895 return (error);
896 goto restart;
897 }
898dontblock:
899 if (uio->uio_td)
900 uio->uio_td->td_proc->p_stats->p_ru.ru_msgrcv++;
901 nextrecord = m->m_nextpkt;
902 if (pr->pr_flags & PR_ADDR) {
903 KASSERT(m->m_type == MT_SONAME,
904 ("m->m_type == %d", m->m_type));
905 orig_resid = 0;
906 if (psa)
907 *psa = dup_sockaddr(mtod(m, struct sockaddr *),
908 mp0 == 0);
--- 25 unchanged lines hidden (view full) ---
934 }
935 if (controlp) {
936 orig_resid = 0;
937 while (*controlp != NULL)
938 controlp = &(*controlp)->m_next;
939 }
940 }
941 if (m) {
942 if ((flags & MSG_PEEK) == 0)
943 m->m_nextpkt = nextrecord;
944 type = m->m_type;
945 if (type == MT_OOBDATA)
946 flags |= MSG_OOB;
947 }
948 moff = 0;
949 offset = 0;
950 while (m && uio->uio_resid > 0 && error == 0) {
951 if (m->m_type == MT_OOBDATA) {
952 if (type != MT_OOBDATA)
953 break;
954 } else if (type == MT_OOBDATA)
955 break;
--- 10 unchanged lines hidden (view full) ---
966 * If mp is set, just pass back the mbufs.
967 * Otherwise copy them out via the uio, then free.
968 * Sockbuf must be consistent here (points to current mbuf,
969 * it points to next record) when we drop priority;
970 * we must note any additions to the sockbuf when we
971 * block interrupts again.
972 */
973 if (mp == 0) {
974 splx(s);
975#ifdef ZERO_COPY_SOCKETS
976 if (so_zero_copy_receive) {
977 vm_page_t pg;
978 int disposable;
979
980 if ((m->m_flags & M_EXT)
981 && (m->m_ext.ext_type == EXT_DISPOSABLE))
--- 31 unchanged lines hidden (view full) ---
1013 *mp = m;
1014 mp = &m->m_next;
1015 so->so_rcv.sb_mb = m = m->m_next;
1016 *mp = (struct mbuf *)0;
1017 } else {
1018 so->so_rcv.sb_mb = m_free(m);
1019 m = so->so_rcv.sb_mb;
1020 }
1021 if (m)
1022 m->m_nextpkt = nextrecord;
1023 }
1024 } else {
1025 if (flags & MSG_PEEK)
1026 moff += len;
1027 else {
1028 if (mp)
1029 *mp = m_copym(m, 0, len, M_TRYWAIT);
1030 m->m_data += len;
--- 28 unchanged lines hidden (view full) ---
1059 if (so->so_error || so->so_state & SS_CANTRCVMORE)
1060 break;
1061 /*
1062 * Notify the protocol that some data has been
1063 * drained before blocking.
1064 */
1065 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
1066 (*pr->pr_usrreqs->pru_rcvd)(so, flags);
1067 error = sbwait(&so->so_rcv);
1068 if (error) {
1069 sbunlock(&so->so_rcv);
1070 splx(s);
1071 return (0);
1072 }
1073 m = so->so_rcv.sb_mb;
1074 if (m)
1075 nextrecord = m->m_nextpkt;
1076 }
1077 }
1078
1079 if (m && pr->pr_flags & PR_ATOMIC) {
1080 flags |= MSG_TRUNC;
1081 if ((flags & MSG_PEEK) == 0)
1082 (void) sbdroprecord(&so->so_rcv);
1083 }
1084 if ((flags & MSG_PEEK) == 0) {
1085 if (m == 0)
1086 so->so_rcv.sb_mb = nextrecord;
1087 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
1088 (*pr->pr_usrreqs->pru_rcvd)(so, flags);
1089 }
1090 if (orig_resid == uio->uio_resid && orig_resid &&
1091 (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
1092 sbunlock(&so->so_rcv);
1093 splx(s);
1094 goto restart;
--- 763 unchanged lines hidden ---
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
--- 20 unchanged lines hidden (view full) ---
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 121307 2003-10-21 18:28:36Z silby $");
38
39#include "opt_inet.h"
40#include "opt_mac.h"
41#include "opt_zero.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/fcntl.h>
--- 837 unchanged lines hidden (view full) ---
883 goto release;
884 }
885 if (uio->uio_resid == 0)
886 goto release;
887 if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
888 error = EWOULDBLOCK;
889 goto release;
890 }
891 sbunlock(&so->so_rcv);
892 error = sbwait(&so->so_rcv);
893 splx(s);
894 if (error)
895 return (error);
896 goto restart;
897 }
898dontblock:
899 if (uio->uio_td)
900 uio->uio_td->td_proc->p_stats->p_ru.ru_msgrcv++;
901 nextrecord = m->m_nextpkt;
902 if (pr->pr_flags & PR_ADDR) {
903 KASSERT(m->m_type == MT_SONAME,
904 ("m->m_type == %d", m->m_type));
905 orig_resid = 0;
906 if (psa)
907 *psa = dup_sockaddr(mtod(m, struct sockaddr *),
908 mp0 == 0);
--- 25 unchanged lines hidden (view full) ---
934 }
935 if (controlp) {
936 orig_resid = 0;
937 while (*controlp != NULL)
938 controlp = &(*controlp)->m_next;
939 }
940 }
941 if (m) {
942 if ((flags & MSG_PEEK) == 0)
943 m->m_nextpkt = nextrecord;
944 type = m->m_type;
945 if (type == MT_OOBDATA)
946 flags |= MSG_OOB;
947 }
948 moff = 0;
949 offset = 0;
950 while (m && uio->uio_resid > 0 && error == 0) {
951 if (m->m_type == MT_OOBDATA) {
952 if (type != MT_OOBDATA)
953 break;
954 } else if (type == MT_OOBDATA)
955 break;
--- 10 unchanged lines hidden (view full) ---
966 * If mp is set, just pass back the mbufs.
967 * Otherwise copy them out via the uio, then free.
968 * Sockbuf must be consistent here (points to current mbuf,
969 * it points to next record) when we drop priority;
970 * we must note any additions to the sockbuf when we
971 * block interrupts again.
972 */
973 if (mp == 0) {
974 splx(s);
975#ifdef ZERO_COPY_SOCKETS
976 if (so_zero_copy_receive) {
977 vm_page_t pg;
978 int disposable;
979
980 if ((m->m_flags & M_EXT)
981 && (m->m_ext.ext_type == EXT_DISPOSABLE))
--- 31 unchanged lines hidden (view full) ---
1013 *mp = m;
1014 mp = &m->m_next;
1015 so->so_rcv.sb_mb = m = m->m_next;
1016 *mp = (struct mbuf *)0;
1017 } else {
1018 so->so_rcv.sb_mb = m_free(m);
1019 m = so->so_rcv.sb_mb;
1020 }
1021 if (m)
1022 m->m_nextpkt = nextrecord;
1023 }
1024 } else {
1025 if (flags & MSG_PEEK)
1026 moff += len;
1027 else {
1028 if (mp)
1029 *mp = m_copym(m, 0, len, M_TRYWAIT);
1030 m->m_data += len;
--- 28 unchanged lines hidden (view full) ---
1059 if (so->so_error || so->so_state & SS_CANTRCVMORE)
1060 break;
1061 /*
1062 * Notify the protocol that some data has been
1063 * drained before blocking.
1064 */
1065 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
1066 (*pr->pr_usrreqs->pru_rcvd)(so, flags);
1067 error = sbwait(&so->so_rcv);
1068 if (error) {
1069 sbunlock(&so->so_rcv);
1070 splx(s);
1071 return (0);
1072 }
1073 m = so->so_rcv.sb_mb;
1074 if (m)
1075 nextrecord = m->m_nextpkt;
1076 }
1077 }
1078
1079 if (m && pr->pr_flags & PR_ATOMIC) {
1080 flags |= MSG_TRUNC;
1081 if ((flags & MSG_PEEK) == 0)
1082 (void) sbdroprecord(&so->so_rcv);
1083 }
1084 if ((flags & MSG_PEEK) == 0) {
1085 if (m == 0)
1086 so->so_rcv.sb_mb = nextrecord;
1087 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
1088 (*pr->pr_usrreqs->pru_rcvd)(so, flags);
1089 }
1090 if (orig_resid == uio->uio_resid && orig_resid &&
1091 (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
1092 sbunlock(&so->so_rcv);
1093 splx(s);
1094 goto restart;
--- 763 unchanged lines hidden ---