[BACK]Return to uipc_socket.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/kern/uipc_socket.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 1993/03/21 09:45:37 version 1.1.1.2, 1998/03/01 02:09:51
Line 1 
Line 1 
 /*  /*
  * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.   * Copyright (c) 1982, 1986, 1988, 1990, 1993
  * All rights reserved.   *      The Regents of the University of California.  All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 30 
Line 30 
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.   * SUCH DAMAGE.
  *   *
  *      @(#)uipc_socket.c       7.28 (Berkeley) 5/4/91   *      @(#)uipc_socket.c       8.3 (Berkeley) 4/15/94
  */   */
   
 #include "param.h"  #include <sys/param.h>
 #include "proc.h"  #include <sys/systm.h>
 #include "file.h"  #include <sys/proc.h>
 #include "malloc.h"  #include <sys/file.h>
 #include "mbuf.h"  #include <sys/malloc.h>
 #include "domain.h"  #include <sys/mbuf.h>
 #include "kernel.h"  #include <sys/domain.h>
 #include "protosw.h"  #include <sys/kernel.h>
 #include "socket.h"  #include <sys/protosw.h>
 #include "socketvar.h"  #include <sys/socket.h>
 #include "resourcevar.h"  #include <sys/socketvar.h>
   #include <sys/resourcevar.h>
   
 /*  /*
  * Socket operation routines.   * Socket operation routines.
Line 54 
Line 55 
  */   */
 /*ARGSUSED*/  /*ARGSUSED*/
 socreate(dom, aso, type, proto)  socreate(dom, aso, type, proto)
           int dom;
         struct socket **aso;          struct socket **aso;
         register int type;          register int type;
         int proto;          int proto;
Line 67  socreate(dom, aso, type, proto)
Line 69  socreate(dom, aso, type, proto)
                 prp = pffindproto(dom, proto, type);                  prp = pffindproto(dom, proto, type);
         else          else
                 prp = pffindtype(dom, type);                  prp = pffindtype(dom, type);
         if (prp == 0)          if (prp == 0 || prp->pr_usrreq == 0)
                 return (EPROTONOSUPPORT);                  return (EPROTONOSUPPORT);
         if (prp->pr_type != type)          if (prp->pr_type != type)
                 return (EPROTOTYPE);                  return (EPROTOTYPE);
Line 282  bad:
Line 284  bad:
         return (error);          return (error);
 }  }
   
   #define SBLOCKWAIT(f)   (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
 /*  /*
  * Send on a socket.   * Send on a socket.
  * If send must go all at once and message is larger than   * If send must go all at once and message is larger than
Line 318  sosend(so, addr, uio, top, control, flag
Line 321  sosend(so, addr, uio, top, control, flag
                 resid = uio->uio_resid;                  resid = uio->uio_resid;
         else          else
                 resid = top->m_pkthdr.len;                  resid = top->m_pkthdr.len;
           /*
            * In theory resid should be unsigned.
            * However, space must be signed, as it might be less than 0
            * if we over-committed, and we must use a signed comparison
            * of space and resid.  On the other hand, a negative resid
            * causes us to loop sending 0-length segments to the protocol.
            */
           if (resid < 0)
                   return (EINVAL);
         dontroute =          dontroute =
             (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&              (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
             (so->so_proto->pr_flags & PR_ATOMIC);              (so->so_proto->pr_flags & PR_ATOMIC);
Line 327  sosend(so, addr, uio, top, control, flag
Line 339  sosend(so, addr, uio, top, control, flag
 #define snderr(errno)   { error = errno; splx(s); goto release; }  #define snderr(errno)   { error = errno; splx(s); goto release; }
   
 restart:  restart:
         if (error = sblock(&so->so_snd))          if (error = sblock(&so->so_snd, SBLOCKWAIT(flags)))
                 goto out;                  goto out;
         do {          do {
                 s = splnet();                  s = splnet();
Line 346  restart:
Line 358  restart:
                 space = sbspace(&so->so_snd);                  space = sbspace(&so->so_snd);
                 if (flags & MSG_OOB)                  if (flags & MSG_OOB)
                         space += 1024;                          space += 1024;
                 if (space < resid + clen &&                  if (atomic && resid > so->so_snd.sb_hiwat ||
                       clen > so->so_snd.sb_hiwat)
                           snderr(EMSGSIZE);
                   if (space < resid + clen && uio &&
                     (atomic || space < so->so_snd.sb_lowat || space < clen)) {                      (atomic || space < so->so_snd.sb_lowat || space < clen)) {
                         if (atomic && resid > so->so_snd.sb_hiwat ||  
                             clen > so->so_snd.sb_hiwat)  
                                 snderr(EMSGSIZE);  
                         if (so->so_state & SS_NBIO)                          if (so->so_state & SS_NBIO)
                                 snderr(EWOULDBLOCK);                                  snderr(EWOULDBLOCK);
                         sbunlock(&so->so_snd);                          sbunlock(&so->so_snd);
Line 389  restart:
Line 401  restart:
 #ifdef  MAPPED_MBUFS  #ifdef  MAPPED_MBUFS
                                 len = min(MCLBYTES, resid);                                  len = min(MCLBYTES, resid);
 #else  #else
                                 if (top == 0) {                                  if (atomic && top == 0) {
                                         len = min(MCLBYTES - max_hdr, resid);                                          len = min(MCLBYTES - max_hdr, resid);
                                         m->m_data += max_hdr;                                          m->m_data += max_hdr;
                                 } else                                  } else
Line 473  soreceive(so, paddr, uio, mp0, controlp,
Line 485  soreceive(so, paddr, uio, mp0, controlp,
         struct mbuf **controlp;          struct mbuf **controlp;
         int *flagsp;          int *flagsp;
 {  {
         struct proc *p = curproc;               /* XXX */  
         register struct mbuf *m, **mp;          register struct mbuf *m, **mp;
         register int flags, len, error, s, offset;          register int flags, len, error, s, offset;
         struct protosw *pr = so->so_proto;          struct protosw *pr = so->so_proto;
         struct mbuf *nextrecord;          struct mbuf *nextrecord;
         int moff, type;          int moff, type;
           int orig_resid = uio->uio_resid;
   
         mp = mp0;          mp = mp0;
         if (paddr)          if (paddr)
Line 512  bad:
Line 524  bad:
                     (struct mbuf *)0, (struct mbuf *)0);                      (struct mbuf *)0, (struct mbuf *)0);
   
 restart:  restart:
         if (error = sblock(&so->so_rcv))          if (error = sblock(&so->so_rcv, SBLOCKWAIT(flags)))
                 return (error);                  return (error);
         s = splnet();          s = splnet();
   
Line 523  restart:
Line 535  restart:
          *   1. the current count is less than the low water mark, or           *   1. the current count is less than the low water mark, or
          *   2. MSG_WAITALL is set, and it is possible to do the entire           *   2. MSG_WAITALL is set, and it is possible to do the entire
          *      receive operation at once if we block (resid <= hiwat).           *      receive operation at once if we block (resid <= hiwat).
            *   3. MSG_DONTWAIT is not set
          * If MSG_WAITALL is set but resid is larger than the receive buffer,           * If MSG_WAITALL is set but resid is larger than the receive buffer,
          * we have to do the receive in sections, and thus risk returning           * we have to do the receive in sections, and thus risk returning
          * a short count if a timeout or signal occurs after we start.           * a short count if a timeout or signal occurs after we start.
          */           */
         while (m == 0 || so->so_rcv.sb_cc < uio->uio_resid &&          if (m == 0 || ((flags & MSG_DONTWAIT) == 0 &&
               so->so_rcv.sb_cc < uio->uio_resid) &&
             (so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||              (so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||
             ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&              ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&
             m->m_nextpkt == 0) {              m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) {
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
                 if (m == 0 && so->so_rcv.sb_cc)                  if (m == 0 && so->so_rcv.sb_cc)
                         panic("receive 1");                          panic("receive 1");
 #endif  #endif
                 if (so->so_error) {                  if (so->so_error) {
                         if (m)                          if (m)
                                 break;                                  goto dontblock;
                         error = so->so_error;                          error = so->so_error;
                         if ((flags & MSG_PEEK) == 0)                          if ((flags & MSG_PEEK) == 0)
                                 so->so_error = 0;                                  so->so_error = 0;
Line 545  restart:
Line 559  restart:
                 }                  }
                 if (so->so_state & SS_CANTRCVMORE) {                  if (so->so_state & SS_CANTRCVMORE) {
                         if (m)                          if (m)
                                 break;                                  goto dontblock;
                         else                          else
                                 goto release;                                  goto release;
                 }                  }
Line 561  restart:
Line 575  restart:
                 }                  }
                 if (uio->uio_resid == 0)                  if (uio->uio_resid == 0)
                         goto release;                          goto release;
                 if (so->so_state & SS_NBIO) {                  if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
                         error = EWOULDBLOCK;                          error = EWOULDBLOCK;
                         goto release;                          goto release;
                 }                  }
Line 573  restart:
Line 587  restart:
                 goto restart;                  goto restart;
         }          }
 dontblock:  dontblock:
         p->p_stats->p_ru.ru_msgrcv++;          if (uio->uio_procp)
                   uio->uio_procp->p_stats->p_ru.ru_msgrcv++;
         nextrecord = m->m_nextpkt;          nextrecord = m->m_nextpkt;
         if (pr->pr_flags & PR_ADDR) {          if (pr->pr_flags & PR_ADDR) {
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
                 if (m->m_type != MT_SONAME)                  if (m->m_type != MT_SONAME)
                         panic("receive 1a");                          panic("receive 1a");
 #endif  #endif
                   orig_resid = 0;
                 if (flags & MSG_PEEK) {                  if (flags & MSG_PEEK) {
                         if (paddr)                          if (paddr)
                                 *paddr = m_copy(m, 0, m->m_len);                                  *paddr = m_copy(m, 0, m->m_len);
Line 618  dontblock:
Line 634  dontblock:
                                 m = so->so_rcv.sb_mb;                                  m = so->so_rcv.sb_mb;
                         }                          }
                 }                  }
                 if (controlp)                  if (controlp) {
                           orig_resid = 0;
                         controlp = &(*controlp)->m_next;                          controlp = &(*controlp)->m_next;
                   }
         }          }
         if (m) {          if (m) {
                 if ((flags & MSG_PEEK) == 0)                  if ((flags & MSG_PEEK) == 0)
Line 699  dontblock:
Line 717  dontblock:
                                         so->so_state |= SS_RCVATMARK;                                          so->so_state |= SS_RCVATMARK;
                                         break;                                          break;
                                 }                                  }
                         } else                          } else {
                                 offset += len;                                  offset += len;
                                   if (offset == so->so_oobmark)
                                           break;
                           }
                 }                  }
                 if (flags & MSG_EOR)                  if (flags & MSG_EOR)
                         break;                          break;
Line 712  dontblock:
Line 733  dontblock:
                  * Keep sockbuf locked against other readers.                   * Keep sockbuf locked against other readers.
                  */                   */
                 while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 &&                  while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 &&
                     !sosendallatonce(so)) {                      !sosendallatonce(so) && !nextrecord) {
                         if (so->so_error || so->so_state & SS_CANTRCVMORE)                          if (so->so_error || so->so_state & SS_CANTRCVMORE)
                                 break;                                  break;
                         error = sbwait(&so->so_rcv);                          error = sbwait(&so->so_rcv);
Line 725  dontblock:
Line 746  dontblock:
                                 nextrecord = m->m_nextpkt;                                  nextrecord = m->m_nextpkt;
                 }                  }
         }          }
   
           if (m && pr->pr_flags & PR_ATOMIC) {
                   flags |= MSG_TRUNC;
                   if ((flags & MSG_PEEK) == 0)
                           (void) sbdroprecord(&so->so_rcv);
           }
         if ((flags & MSG_PEEK) == 0) {          if ((flags & MSG_PEEK) == 0) {
                 if (m == 0)                  if (m == 0)
                         so->so_rcv.sb_mb = nextrecord;                          so->so_rcv.sb_mb = nextrecord;
                 else if (pr->pr_flags & PR_ATOMIC) {  
                         flags |= MSG_TRUNC;  
                         (void) sbdroprecord(&so->so_rcv);  
                 }  
                 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)                  if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
                         (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,                          (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
                             (struct mbuf *)flags, (struct mbuf *)0,                              (struct mbuf *)flags, (struct mbuf *)0,
                             (struct mbuf *)0);                              (struct mbuf *)0);
         }          }
           if (orig_resid == uio->uio_resid && orig_resid &&
               (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
                   sbunlock(&so->so_rcv);
                   splx(s);
                   goto restart;
           }
   
         if (flagsp)          if (flagsp)
                 *flagsp |= flags;                  *flagsp |= flags;
 release:  release:
Line 769  sorflush(so)
Line 799  sorflush(so)
         struct sockbuf asb;          struct sockbuf asb;
   
         sb->sb_flags |= SB_NOINTR;          sb->sb_flags |= SB_NOINTR;
         (void) sblock(sb);          (void) sblock(sb, M_WAITOK);
         s = splimp();          s = splimp();
         socantrcvmore(so);          socantrcvmore(so);
         sbunlock(sb);          sbunlock(sb);
Line 811  sosetopt(so, level, optname, m0)
Line 841  sosetopt(so, level, optname, m0)
                 case SO_USELOOPBACK:                  case SO_USELOOPBACK:
                 case SO_BROADCAST:                  case SO_BROADCAST:
                 case SO_REUSEADDR:                  case SO_REUSEADDR:
                   case SO_REUSEPORT:
                 case SO_OOBINLINE:                  case SO_OOBINLINE:
                         if (m == NULL || m->m_len < sizeof (int)) {                          if (m == NULL || m->m_len < sizeof (int)) {
                                 error = EINVAL;                                  error = EINVAL;
Line 884  sosetopt(so, level, optname, m0)
Line 915  sosetopt(so, level, optname, m0)
                         error = ENOPROTOOPT;                          error = ENOPROTOOPT;
                         break;                          break;
                 }                  }
                   if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
                           (void) ((*so->so_proto->pr_ctloutput)
                                     (PRCO_SETOPT, so, level, optname, &m0));
                           m = NULL;       /* freed by protocol */
                   }
         }          }
 bad:  bad:
         if (m)          if (m)
Line 922  sogetopt(so, level, optname, mp)
Line 958  sogetopt(so, level, optname, mp)
                 case SO_DEBUG:                  case SO_DEBUG:
                 case SO_KEEPALIVE:                  case SO_KEEPALIVE:
                 case SO_REUSEADDR:                  case SO_REUSEADDR:
                   case SO_REUSEPORT:
                 case SO_BROADCAST:                  case SO_BROADCAST:
                 case SO_OOBINLINE:                  case SO_OOBINLINE:
                         *mtod(m, int *) = so->so_options & optname;                          *mtod(m, int *) = so->so_options & optname;
Line 983  sohasoutofband(so)
Line 1020  sohasoutofband(so)
                 gsignal(-so->so_pgid, SIGURG);                  gsignal(-so->so_pgid, SIGURG);
         else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)          else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)
                 psignal(p, SIGURG);                  psignal(p, SIGURG);
         if (so->so_rcv.sb_sel) {          selwakeup(&so->so_rcv.sb_sel);
                 selwakeup(so->so_rcv.sb_sel, so->so_rcv.sb_flags & SB_COLL);  
                 so->so_rcv.sb_sel = 0;  
                 so->so_rcv.sb_flags &= ~SB_COLL;  
         }  
 }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2

CVSweb <webmaster@jp.NetBSD.org>