+long
+tcp_sbspace(struct tcpcb *tp)
+{
+ struct sockbuf *sb = &tp->t_inpcb->inp_socket->so_rcv;
+ long space, newspace;
+
+ space = ((long) lmin((sb->sb_hiwat - sb->sb_cc),
+ (sb->sb_mbmax - sb->sb_mbcnt)));
+
+#if TRAFFIC_MGT
+ if (tp->t_inpcb->inp_socket->so_traffic_mgt_flags & TRAFFIC_MGT_SO_BACKGROUND) {
+ if (tcp_background_io_enabled &&
+ tp->t_inpcb->inp_socket->so_traffic_mgt_flags & TRAFFIC_MGT_SO_BG_SUPPRESSED) {
+ tp->t_flags |= TF_RXWIN0SENT;
+ return 0; /* Triggers TCP window closing by responding there is no space */
+ }
+ }
+#endif /* TRAFFIC_MGT */
+
+ /* Avoid inscreasing window size if the current window
+ * is already very low, we could be in "persist" mode and
+ * we could break some apps (see rdar://5409343)
+ */
+
+ if (space < tp->t_maxseg)
+ return space;
+
+ /* Clip window size for slower link */
+
+ if (((tp->t_flags & TF_SLOWLINK) != 0) && slowlink_wsize > 0 )
+ return lmin(space, slowlink_wsize);
+
+ /*
+ * Check for ressources constraints before over-ajusting the amount of space we can
+ * advertise in the TCP window size updates.
+ */
+
+ if (sbspace_factor && (tp->t_inpcb->inp_pcbinfo->ipi_count < tcp_sockthreshold) &&
+ (total_mb_cnt / 8) < (mbstat.m_clusters / sbspace_factor)) {
+ if (space < (long)(sb->sb_maxused - sb->sb_cc)) {/* make sure we don't constrain the window if we have enough ressources */
+ space = (long) lmax((sb->sb_maxused - sb->sb_cc), tp->rcv_maxbyps);
+ }
+ newspace = (long) lmax(((long)sb->sb_maxused - sb->sb_cc), (long)tp->rcv_maxbyps);
+
+ if (newspace > space)
+ space = newspace;
+ }
+ return space;
+}
+/* DSEP Review Done pl-20051213-v02 @3253,@3391,@3400 */