Print this page
OS-4602 lxbrand support recvmsg(MSG_PEEK|MSG_TRUNC) behavior
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/sockfs/sockcommon_subr.c
          +++ new/usr/src/uts/common/fs/sockfs/sockcommon_subr.c
↓ open down ↓ 662 lines elided ↑ open up ↑
 663  663          mblk_t  *mp, *nmp;
 664  664          mblk_t  *savemp, *savemptail;
 665  665          mblk_t  *new_msg_head;
 666  666          mblk_t  *new_msg_last_head;
 667  667          mblk_t  *last_tail;
 668  668          boolean_t partial_read;
 669  669          boolean_t reset_atmark = B_FALSE;
 670  670          int more = 0;
 671  671          int error;
 672  672          ssize_t oobmark;
      673 +        ssize_t copied = 0;
 673  674          sodirect_t *sodp = so->so_direct;
      675 +        xuio_t *xuio = NULL;
 674  676  
 675  677          partial_read = B_FALSE;
 676  678          *mctlp = NULL;
      679 +        if ((uiop->uio_extflg & UIO_XUIO) != 0) {
      680 +                xuio = (xuio_t *)uiop;
      681 +        }
 677  682  again:
 678  683          mutex_enter(&so->so_lock);
 679  684  again1:
 680  685  #ifdef DEBUG
 681  686          if (so_debug_length) {
 682  687                  ASSERT(so_check_length(so));
 683  688          }
 684  689  #endif
 685  690          if (so->so_state & SS_RCVATMARK) {
 686  691                  /* Check whether the caller is OK to read past the mark */
↓ open down ↓ 90 lines elided ↑ open up ↑
 777  782                          mp = savemptail->b_cont;
 778  783                          savemptail->b_cont = NULL;
 779  784                  }
 780  785  
 781  786                  ASSERT(DB_TYPE(mp) == M_DATA);
 782  787                  /*
 783  788                   * Now process DATA blocks, if any. Note that for sodirect
 784  789                   * enabled socket, uio_resid can be 0.
 785  790                   */
 786  791                  if (uiop->uio_resid >= 0) {
 787      -                        ssize_t copied = 0;
 788      -
 789  792                          if (sodp != NULL && (DB_FLAGS(mp) & DBLK_UIOA)) {
 790  793                                  mutex_enter(&so->so_lock);
 791  794                                  ASSERT(uiop == (uio_t *)&sodp->sod_uioa);
 792  795                                  copied = sod_uioa_mblk(so, mp);
 793  796                                  if (copied > 0)
 794  797                                          partial_read = B_TRUE;
 795  798                                  mutex_exit(&so->so_lock);
 796  799                                  /* mark this mblk as processed */
 797  800                                  mp = NULL;
 798  801                          } else {
↓ open down ↓ 37 lines elided ↑ open up ↑
 836  839                                  }
 837  840                                  /*
 838  841                                   * so_check_flow_control() will drop
 839  842                                   * so->so_lock.
 840  843                                   */
 841  844                                  rvalp->r_val2 = so_check_flow_control(so);
 842  845                          }
 843  846                  }
 844  847                  if (mp != NULL) { /* more data blocks in msg */
 845  848                          more |= MOREDATA;
      849 +
      850 +                        /*
      851 +                         * If requested, tally up remaining data along with the
      852 +                         * amount already copied.
      853 +                         */
      854 +                        if (xuio != NULL &&
      855 +                            xuio->xu_type == UIOTYPE_PEEKSIZE) {
      856 +                                xuio->xu_ext.xu_ps.xu_ps_set = B_TRUE;
      857 +                                xuio->xu_ext.xu_ps.xu_ps_size =
      858 +                                    copied + msgdsize(mp);
      859 +                        }
      860 +
 846  861                          if ((flags & (MSG_PEEK|MSG_TRUNC))) {
 847  862                                  if (flags & MSG_PEEK) {
 848  863                                          freemsg(mp);
 849  864                                  } else {
 850  865                                          unsigned int msize = msgdsize(mp);
 851  866  
 852  867                                          freemsg(mp);
 853  868                                          mutex_enter(&so->so_lock);
 854  869                                          so->so_rcv_queued -= msize;
 855  870                                          /*
↓ open down ↓ 1603 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX