本文整理汇总了C++中sbspace函数的典型用法代码示例。如果您正苦于以下问题:C++ sbspace函数的具体用法?C++ sbspace怎么用?C++ sbspace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sbspace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: tcp_respond
/*
* Send a single message to the TCP at address specified by
* the given TCP/IP header. If m == 0, then we make a copy
* of the tcpiphdr at ti and send directly to the addressed host.
* This is used to force keep alive messages out using the TCP
* template for a connection tp->t_template. If flags are given
* then we send a message back to the TCP which originated the
* segment ti, and discard the mbuf containing it and any other
* attached mbufs.
*
* In any case the ack and sequence number of the transmitted
* segment are as specified by the parameters.
*/
void
tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m,
tcp_seq ack, tcp_seq seq, int flags, unsigned short af)
{
register int tlen;
int win = 0;
DEBUG_CALL("tcp_respond");
DEBUG_ARG("tp = %p", tp);
DEBUG_ARG("ti = %p", ti);
DEBUG_ARG("m = %p", m);
DEBUG_ARG("ack = %u", ack);
DEBUG_ARG("seq = %u", seq);
DEBUG_ARG("flags = %x", flags);
if (tp)
win = sbspace(&tp->t_socket->so_rcv);
if (m == NULL) {
if (!tp || (m = m_get(tp->t_socket->slirp)) == NULL)
return;
tlen = 0;
m->m_data += IF_MAXLINKHDR;
*mtod(m, struct tcpiphdr *) = *ti;
ti = mtod(m, struct tcpiphdr *);
memset(&ti->ti, 0, sizeof(ti->ti));
flags = TH_ACK;
} else {
开发者ID:8tab,项目名称:qemu,代码行数:40,代码来源:tcp_subr.c
示例2: sbappendcontrol
int
sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control)
{
struct mbuf *m, *mlast, *n;
int space = 0;
if (control == NULL)
panic("sbappendcontrol");
for (m = control; ; m = m->m_next) {
space += m->m_len;
if (m->m_next == NULL)
break;
}
n = m; /* save pointer to last control buffer */
for (m = m0; m; m = m->m_next)
space += m->m_len;
if (space > sbspace(sb))
return (0);
n->m_next = m0; /* concatenate data to control */
SBLASTRECORDCHK(sb, "sbappendcontrol 1");
for (m = control; m->m_next != NULL; m = m->m_next)
sballoc(sb, m);
sballoc(sb, m);
mlast = m;
SBLINKRECORD(sb, control);
sb->sb_mbtail = mlast;
SBLASTMBUFCHK(sb, "sbappendcontrol");
SBLASTRECORDCHK(sb, "sbappendcontrol 2");
return (1);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:35,代码来源:uipc_socket2.c
示例3: tcp_respond
/*
* Send a single message to the TCP at address specified by
* the given TCP/IP header. If m == 0, then we make a copy
* of the tcpiphdr at ti and send directly to the addressed host.
* This is used to force keep alive messages out using the TCP
* template for a connection tp->t_template. If flags are given
* then we send a message back to the TCP which originated the
* segment ti, and discard the mbuf containing it and any other
* attached mbufs.
*
* In any case the ack and sequence number of the transmitted
* segment are as specified by the parameters.
*/
void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, tcp_seq ack, tcp_seq seq, int flags)
{
int tlen;
int win = 0;
DEBUG_CALL("tcp_respond");
DEBUG_ARG("tp = %lx", (long)tp);
DEBUG_ARG("ti = %lx", (long)ti);
DEBUG_ARG("m = %lx", (long)m);
DEBUG_ARG("ack = %u", ack);
DEBUG_ARG("seq = %u", seq);
DEBUG_ARG("flags = %x", flags);
if (tp)
win = sbspace(&tp->t_socket->so_rcv);
if (m == 0) {
if ((m = m_get()) == NULL)
return;
#ifdef TCP_COMPAT_42
tlen = 1;
#else
tlen = 0;
#endif
m->m_data += if_maxlinkhdr;
*mtod(m, struct tcpiphdr *) = *ti;
ti = mtod(m, struct tcpiphdr *);
flags = TH_ACK;
} else {
开发者ID:engur,项目名称:WinUAE,代码行数:41,代码来源:tcp_subr.cpp
示例4: tcp_respond
/*
* Send a single message to the TCP at address specified by
* the given TCP/IP header. If m == 0, then we make a copy
* of the tcpiphdr at ti and send directly to the addressed host.
* This is used to force keep alive messages out using the TCP
* template for a connection tp->t_template. If flags are given
* then we send a message back to the TCP which originated the
* segment ti, and discard the mbuf containing it and any other
* attached mbufs.
*
* In any case the ack and sequence number of the transmitted
* segment are as specified by the parameters.
*/
void
tcp_respond(PNATState pData, struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, tcp_seq ack, tcp_seq seq, int flags)
{
register int tlen;
int win = 0;
LogFlowFunc(("ENTER: tp = %R[tcpcb793], ti = %lx, m = %lx, ack = %u, seq = %u, flags = %x\n",
tp, (long)ti, (long)m, ack, seq, flags));
if (tp)
win = sbspace(&tp->t_socket->so_rcv);
if (m == 0)
{
if ((m = m_gethdr(pData, M_DONTWAIT, MT_HEADER)) == NULL)
return;
#ifdef TCP_COMPAT_42
tlen = 1;
#else
tlen = 0;
#endif
m->m_data += if_maxlinkhdr;
m->m_pkthdr.header = mtod(m, void *);
*mtod(m, struct tcpiphdr *) = *ti;
ti = mtod(m, struct tcpiphdr *);
flags = TH_ACK;
}
else
{
开发者ID:VirtualMonitor,项目名称:VirtualMonitor,代码行数:41,代码来源:tcp_subr.c
示例5: rfcomm_attach
static int
rfcomm_attach(struct socket *so, int proto)
{
int error;
KASSERT(so->so_pcb == NULL);
if (so->so_lock == NULL) {
mutex_obj_hold(bt_lock);
so->so_lock = bt_lock;
solock(so);
}
KASSERT(solocked(so));
/*
* Since we have nothing to add, we attach the DLC
* structure directly to our PCB pointer.
*/
error = soreserve(so, rfcomm_sendspace, rfcomm_recvspace);
if (error)
return error;
error = rfcomm_attach_pcb((struct rfcomm_dlc **)&so->so_pcb,
&rfcomm_proto, so);
if (error)
return error;
error = rfcomm_rcvd_pcb(so->so_pcb, sbspace(&so->so_rcv));
if (error) {
rfcomm_detach_pcb((struct rfcomm_dlc **)&so->so_pcb);
return error;
}
return 0;
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:34,代码来源:rfcomm_socket.c
示例6: sbappendcontrol_locked
int
sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control)
{
struct mbuf *m, *n, *mlast;
int space;
SOCKBUF_LOCK_ASSERT(sb);
if (control == 0)
panic("sbappendcontrol_locked");
space = m_length(control, &n) + m_length(m0, NULL);
if (space > sbspace(sb))
return (0);
n->m_next = m0; /* concatenate data to control */
SBLASTRECORDCHK(sb);
for (m = control; m->m_next; m = m->m_next)
sballoc(sb, m);
sballoc(sb, m);
mlast = m;
SBLINKRECORD(sb, control);
sb->sb_mbtail = mlast;
SBLASTMBUFCHK(sb);
SBLASTRECORDCHK(sb);
return (1);
}
开发者ID:diegows,项目名称:wanproxy,代码行数:31,代码来源:uipc_sockbuf.c
示例7: fifo_freespace
/* You'd certainly better have an iocount on the vnode! */
int
fifo_freespace(struct vnode *vp, long *count)
{
struct socket *rsock;
rsock = vp->v_fifoinfo->fi_readsock;
socket_lock(rsock, 1);
*count = sbspace(&rsock->so_rcv);
socket_unlock(rsock, 1);
return 0;
}
开发者ID:onlynone,项目名称:xnu,代码行数:11,代码来源:fifo_vnops.c
示例8: natmintr
/*
* natmintr: interrupt
*
* Note: we expect a socket pointer in rcvif rather than an interface
* pointer. We can get the interface pointer from the so's PCB if we really
* need it.
*/
void
natmintr(struct mbuf *m)
{
struct socket *so;
struct natmpcb *npcb;
#ifdef DIAGNOSTIC
M_ASSERTPKTHDR(m);
#endif
NATM_LOCK();
npcb = (struct natmpcb *)m->m_pkthdr.rcvif; /* XXX: overloaded */
so = npcb->npcb_socket;
npcb->npcb_inq--;
if (npcb->npcb_flags & NPCB_DRAIN) {
if (npcb->npcb_inq == 0)
free(npcb, M_PCB); /* done! */
NATM_UNLOCK();
m_freem(m);
return;
}
if (npcb->npcb_flags & NPCB_FREE) {
NATM_UNLOCK();
m_freem(m); /* drop */
return;
}
#ifdef NEED_TO_RESTORE_IFP
m->m_pkthdr.rcvif = npcb->npcb_ifp;
#else
#ifdef DIAGNOSTIC
m->m_pkthdr.rcvif = NULL; /* null it out to be safe */
#endif
#endif
if (sbspace(&so->so_rcv) > m->m_pkthdr.len) {
#ifdef NATM_STAT
natm_sookcnt++;
natm_sookbytes += m->m_pkthdr.len;
#endif
sbappendrecord(&so->so_rcv, m);
sorwakeup(so);
NATM_UNLOCK();
} else {
#ifdef NATM_STAT
natm_sodropcnt++;
natm_sodropbytes += m->m_pkthdr.len;
#endif
NATM_UNLOCK();
m_freem(m);
}
}
开发者ID:DangerDexter,项目名称:FreeBSD-8.0-dyntick,代码行数:62,代码来源:natm.c
示例9: rfcomm_rcvd
static int
rfcomm_rcvd(struct socket *so, int flags, struct lwp *l)
{
struct rfcomm_dlc *pcb = so->so_pcb;
KASSERT(solocked(so));
if (pcb == NULL)
return EINVAL;
return rfcomm_rcvd_pcb(pcb, sbspace(&so->so_rcv));
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:12,代码来源:rfcomm_socket.c
示例10: filt_fifowrite
int
filt_fifowrite(struct knote *kn, long hint)
{
struct socket *so = (struct socket *)kn->kn_hook;
kn->kn_data = sbspace(&so->so_snd);
if (so->so_state & SS_CANTSENDMORE) {
kn->kn_flags |= EV_EOF;
return (1);
}
kn->kn_flags &= ~EV_EOF;
return (kn->kn_data >= so->so_snd.sb_lowat);
}
开发者ID:7shi,项目名称:openbsd-loongson-vc,代码行数:13,代码来源:fifo_vnops.c
示例11: sbappendaddr
/*
* Append address and data, and optionally, control (ancillary) data
* to the receive queue of a socket. If present,
* m0 must include a packet header with total length.
* Returns 0 if no space in sockbuf or insufficient mbufs.
*/
int
sbappendaddr(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0,
struct mbuf *control)
{
struct mbuf *m, *n, *nlast;
int space = asa->sa_len;
if (m0 && (m0->m_flags & M_PKTHDR) == 0)
panic("sbappendaddr");
if (m0)
space += m0->m_pkthdr.len;
for (n = control; n; n = n->m_next) {
space += n->m_len;
if (n->m_next == NULL) /* keep pointer to last control buf */
break;
}
if (space > sbspace(sb))
return (0);
if (asa->sa_len > MLEN)
return (0);
MGET(m, M_DONTWAIT, MT_SONAME);
if (m == NULL)
return (0);
m->m_len = asa->sa_len;
memcpy(mtod(m, caddr_t), asa, asa->sa_len);
if (n)
n->m_next = m0; /* concatenate data to control */
else
control = m0;
m->m_next = control;
SBLASTRECORDCHK(sb, "sbappendaddr 1");
for (n = m; n->m_next != NULL; n = n->m_next)
sballoc(sb, n);
sballoc(sb, n);
nlast = n;
SBLINKRECORD(sb, m);
sb->sb_mbtail = nlast;
SBLASTMBUFCHK(sb, "sbappendaddr");
SBLASTRECORDCHK(sb, "sbappendaddr 2");
return (1);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:52,代码来源:uipc_socket2.c
示例12: sbappendaddr_locked
/*
* Append address and data, and optionally, control (ancillary) data to the
* receive queue of a socket. If present, m0 must include a packet header
* with total length. Returns 0 if no space in sockbuf or insufficient
* mbufs.
*/
int
sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control)
{
struct mbuf *m, *n, *nlast;
int space = asa->sa_len;
SOCKBUF_LOCK_ASSERT(sb);
if (m0 && (m0->m_flags & M_PKTHDR) == 0)
panic("sbappendaddr_locked");
if (m0)
space += m0->m_pkthdr.len;
space += m_length(control, &n);
if (space > sbspace(sb))
return (0);
#if MSIZE <= 256
if (asa->sa_len > MLEN)
return (0);
#endif
MGET(m, M_DONTWAIT, MT_SONAME);
if (m == 0)
return (0);
m->m_len = asa->sa_len;
bcopy(asa, mtod(m, caddr_t), asa->sa_len);
if (n){
CHECK_ADD_LINKCNT(n, m0, NULL, "sbappendaddr_locked");
n->m_next = m0; /* concatenate data to control */
}else
control = m0;
CHECK_ADD_LINKCNT(m, control, NULL, "sbappendaddr_locked");
m->m_next = control;
for (n = m; n->m_next != NULL; n = n->m_next)
sballoc(sb, n);
sballoc(sb, n);
nlast = n;
SBLINKRECORD(sb, m);
sb->sb_mbtail = nlast;
SBLASTMBUFCHK(sb);
SBLASTRECORDCHK(sb);
return (1);
}
开发者ID:Multi2Sim,项目名称:m2s-bench-parsec-3.0-src,代码行数:51,代码来源:uipc_sockbuf.c
示例13: key_receive
key_receive(struct socket *so, struct mbuf **paddr, struct uio *uio,
struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
#endif
{
struct rawcb *rp = sotorawcb(so);
struct keycb *kp = (struct keycb *)rp;
int error;
#ifndef __FreeBSD__
error = (*kp->kp_receive)(so, paddr, uio, mp0, controlp, flagsp);
#else
error = soreceive(so, paddr, uio, mp0, controlp, flagsp);
#endif
if (kp->kp_queue &&
sbspace(&rp->rcb_socket->so_rcv) > kp->kp_queue->m_pkthdr.len)
sorwakeup(so);
return error;
}
开发者ID:MarginC,项目名称:kame,代码行数:19,代码来源:keysock.c
示例14: sbappendaddr_locked
/*
* Append address and data, and optionally, control (ancillary) data to the
* receive queue of a socket. If present, m0 must include a packet header
* with total length. Returns 0 if no space in sockbuf or insufficient
* mbufs.
*/
int
sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control)
{
struct mbuf *ctrl_last;
int space = asa->sa_len;
SOCKBUF_LOCK_ASSERT(sb);
if (m0 && (m0->m_flags & M_PKTHDR) == 0)
panic("sbappendaddr_locked");
if (m0)
space += m0->m_pkthdr.len;
space += m_length(control, &ctrl_last);
if (space > sbspace(sb))
return (0);
return (sbappendaddr_locked_internal(sb, asa, m0, control, ctrl_last));
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:25,代码来源:uipc_sockbuf.c
示例15: tcp_input
//.........这里部分代码省略.........
SEQ_GT(ti->ti_ack, tp->t_rtseq))
tcp_xmit_timer(tp, tp->t_rtt);
acked = ti->ti_ack - tp->snd_una;
sbdrop(&so->so_snd, acked);
tp->snd_una = ti->ti_ack;
m_free(m);
/*
* If all outstanding data are acked, stop
* retransmit timer, otherwise restart timer
* using current (possibly backed-off) value.
* If process is waiting for space,
* wakeup/selwakeup/signal. If data
* are ready to send, let tcp_output
* decide between more output or persist.
*/
if (tp->snd_una == tp->snd_max)
tp->t_timer[TCPT_REXMT] = 0;
else if (tp->t_timer[TCPT_PERSIST] == 0)
tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
/*
* This is called because sowwakeup might have
* put data into so_snd. Since we don't so sowwakeup,
* we don't need this.. XXX???
*/
if (so->so_snd.sb_cc)
(void) tcp_output(tp);
return;
}
} else if (ti->ti_ack == tp->snd_una &&
tcpfrag_list_empty(tp) &&
ti->ti_len <= sbspace(&so->so_rcv)) {
/*
* this is a pure, in-sequence data packet
* with nothing on the reassembly queue and
* we have enough buffer space to take it.
*/
tp->rcv_nxt += ti->ti_len;
/*
* Add data to socket buffer.
*/
if (so->so_emu) {
if (tcp_emu(so,m)) sbappend(so, m);
} else
sbappend(so, m);
/*
* If this is a short packet, then ACK now - with Nagel
* congestion avoidance sender won't send more until
* he gets an ACK.
*
* It is better to not delay acks at all to maximize
* TCP throughput. See RFC 2581.
*/
tp->t_flags |= TF_ACKNOW;
tcp_output(tp);
return;
}
} /* header prediction */
/*
* Calculate amount of space in receive window,
* and then do TCP input processing.
* Receive window is amount of space in rcv queue,
* but not less than advertised window.
开发者ID:AnselZhangGit,项目名称:qemu_stm32,代码行数:67,代码来源:tcp_input.c
示例16: tcp_output
//.........这里部分代码省略.........
len = 0;
if (win == 0)
{
tp->t_timer[TCPT_REXMT] = 0;
tp->snd_nxt = tp->snd_una;
}
}
if (len > (int)tp->t_maxseg)
{
len = tp->t_maxseg;
sendalot = 1;
}
#ifdef IP_V4
#ifdef IP_PMTU
{
int pmtu = tp->t_inpcb->inp_pmtu - 40;
if (len > pmtu)
{
len = pmtu - 40;
sendalot = 1;
}
}
#endif /* IP_PMTU */
/* We don't need a pmtu test for IPv6. V6 code limits t_maxseg to
* the Path MTU, so the test above the v4 ifdef above covers us.
*/
#endif /* IP_V4 */
if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
flags &= ~TH_FIN;
win = (long)(sbspace(&so->so_rcv));
/*
* If our state indicates that FIN should be sent
* and we have not yet done so, or we're retransmitting the FIN,
* then we need to send.
*/
if ((flags & TH_FIN) &&
(so->so_snd.sb_cc == 0) &&
((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
{
goto send;
}
/*
* Send if we owe peer an ACK.
*/
if (tp->t_flags & TF_ACKNOW)
goto send;
if (flags & (TH_SYN|TH_RST))
goto send;
if (SEQ_GT(tp->snd_up, tp->snd_una))
goto send;
/*
* Sender silly window avoidance. If connection is idle
* and can send all data, a maximum segment,
* at least a maximum default-size segment do it,
* or are forced, do it; otherwise don't bother.
* If peer's buffer is tiny, then send
* when window is at least half open.
* If retransmitting (possibly after persist timer forced us
* to send into a small window), then must resend.
*/
开发者ID:fjanssen,项目名称:Car2X,代码行数:67,代码来源:tcp_out.c
示例17: natmintr
void
natmintr()
{
int s;
struct mbuf *m;
struct socket *so;
struct natmpcb *npcb;
next:
s = splnet();
IF_DEQUEUE(&natmintrq, m);
splx(s);
if (m == NULL)
return;
#ifdef DIAGNOSTIC
if ((m->m_flags & M_PKTHDR) == 0)
panic("natmintr no HDR");
#endif
npcb = (struct natmpcb *) m->m_pkthdr.rcvif; /* XXX: overloaded */
so = npcb->npcb_socket;
s = splnet(); /* could have atm devs @ different levels */
npcb->npcb_inq--;
splx(s);
if (npcb->npcb_flags & NPCB_DRAIN) {
m_freem(m);
if (npcb->npcb_inq == 0)
free(npcb, M_PCB); /* done! */
goto next;
}
if (npcb->npcb_flags & NPCB_FREE) {
m_freem(m); /* drop */
goto next;
}
#ifdef NEED_TO_RESTORE_IFP
m->m_pkthdr.rcvif = npcb->npcb_ifp;
#else
#ifdef DIAGNOSTIC
m->m_pkthdr.rcvif = NULL; /* null it out to be safe */
#endif
#endif
if (sbspace(&so->so_rcv) > m->m_pkthdr.len ||
((npcb->npcb_flags & NPCB_RAW) != 0 && so->so_rcv.sb_cc < NPCB_RAWCC) ) {
#ifdef NATM_STAT
natm_sookcnt++;
natm_sookbytes += m->m_pkthdr.len;
#endif
sbappendrecord(&so->so_rcv, m);
sorwakeup(so);
} else {
#ifdef NATM_STAT
natm_sodropcnt++;
natm_sodropbytes += m->m_pkthdr.len;
#endif
m_freem(m);
}
goto next;
}
开发者ID:sofuture,项目名称:bitrig,代码行数:66,代码来源:natm.c
示例18: sbappendaddr
/*
* Append address and data, and optionally, control (ancillary) data
* to the receive queue of a socket. If present,
* m0 must include a packet header with total length.
* Returns 0 if no space in sockbuf or insufficient mbufs.
*/
int
sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0,
struct mbuf *control)
{
struct mbuf *m, *n, *nlast;
int space, len;
KASSERT(solocked(sb->sb_so));
space = asa->sa_len;
if (m0 != NULL) {
if ((m0->m_flags & M_PKTHDR) == 0)
panic("sbappendaddr");
space += m0->m_pkthdr.len;
#ifdef MBUFTRACE
m_claimm(m0, sb->sb_mowner);
#endif
}
for (n = control; n; n = n->m_next) {
space += n->m_len;
MCLAIM(n, sb->sb_mowner);
if (n->m_next == 0) /* keep pointer to last control buf */
break;
}
if (space > sbspace(sb))
return (0);
MGET(m, M_DONTWAIT, MT_SONAME);
if (m == 0)
return (0);
MCLAIM(m, sb->sb_mowner);
/*
* XXX avoid 'comparison always true' warning which isn't easily
* avoided.
*/
len = asa->sa_len;
if (len > MLEN) {
MEXTMALLOC(m, asa->sa_len, M_NOWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_free(m);
return (0);
}
}
m->m_len = asa->sa_len;
memcpy(mtod(m, void *), asa, asa->sa_len);
if (n)
n->m_next = m0; /* concatenate data to control */
else
control = m0;
m->m_next = control;
SBLASTRECORDCHK(sb, "sbappendaddr 1");
for (n = m; n->m_next != NULL; n = n->m_next)
sballoc(sb, n);
sballoc(sb, n);
nlast = n;
SBLINKRECORD(sb, m);
sb->sb_mbtail = nlast;
SBLASTMBUFCHK(sb, "sbappendaddr");
SBLASTRECORDCHK(sb, "sbappendaddr 2");
return (1);
}
开发者ID:bigclouds,项目名称:netbsd_dpdk_port,代码行数:71,代码来源:uipc_socket2.c
示例19: sbappendaddrchain
int
sbappendaddrchain(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, int sbprio)
{
int space;
struct mbuf *m, *n, *n0, *nlast;
int error;
KASSERT(solocked(sb->sb_so));
/*
* XXX sbprio reserved for encoding priority of this* request:
* SB_PRIO_NONE --> honour normal sb limits
* SB_PRIO_ONESHOT_OVERFLOW --> if socket has any space,
* take whole chain. Intended for large requests
* that should be delivered atomically (all, or none).
* SB_PRIO_OVERDRAFT -- allow a small (2*MLEN) overflow
* over normal socket limits, for messages indicating
* buffer overflow in earlier normal/lower-priority messages
* SB_PRIO_BESTEFFORT --> ignore limits entirely.
* Intended for kernel-generated messages only.
* Up to generator to avoid total mbuf resource exhaustion.
*/
(void)sbprio;
if (m0 && (m0->m_flags & M_PKTHDR) == 0)
panic("sbappendaddrchain");
space = sbspace(sb);
#ifdef notyet
/*
* Enforce SB_PRIO_* limits as described above.
*/
#endif
n0 = NULL;
nlast = NULL;
for (m = m0; m; m = m->m_nextpkt) {
struct mbuf *np;
#ifdef MBUFTRACE
m_claimm(m, sb->sb_mowner);
#endif
/* Prepend sockaddr to this record (m) of input chain m0 */
n = m_prepend_sockaddr(sb, m, asa);
if (n == NULL) {
error = ENOBUFS;
goto bad;
}
/* Append record (asa+m) to end of new chain n0 */
if (n0 == NULL) {
n0 = n;
} else {
nlast->m_nextpkt = n;
}
/* Keep track of last record on new chain */
nlast = n;
for (np = n; np; np = np->m_next)
sballoc(sb, np);
}
SBLASTRECORDCHK(sb, "sbappendaddrchain 1");
/* Drop the entire chain of (asa+m) records onto the socket */
SBLINKRECORDCHAIN(sb, n0, nlast);
SBLASTRECORDCHK(sb, "sbappendaddrchain 2");
for (m = nlast; m->m_next; m = m->m_next)
;
sb->sb_mbtail = m;
SBLASTMBUFCHK(sb, "sbappendaddrchain");
return (1);
bad:
/*
* On error, free the prepended addreseses. For consistency
* with sbappendaddr(), leave it to our caller to free
* the input record chain passed to us as m0.
*/
while ((n = n0) != NULL) {
struct mbuf *np;
/* Undo the sballoc() of this record */
for (np = n; np; np = np->m_next)
sbfree(sb, np);
n0 = n->m_nextpkt; /* iterate at next prepended address */
MFREE(n, np); /* free prepended address (not data) */
}
return 0;
}
开发者ID:bigclouds,项目名称:netbsd_dpdk_port,代码行数:97,代码来源:uipc_socket2.c
示例20: sosend
int
sosend(struct socket *so,
struct mbuf *nam, /* sockaddr, if UDP socket, NULL if TCP */
char *data, /* data to send */
int *data_length, /* IN/OUT length of (remaining) data */
int flags)
{
struct mbuf *head = (struct mbuf *)NULL;
struct mbuf *m;
int space;
int resid;
int len;
int error = 0;
int dontroute;
int first = 1;
resid = *data_length;
/*
* 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);
INET_TRACE (INETM_IO, ("INET:sosend: so %lx resid %d sb_hiwat %d so_state %x\n",
so, resid, so->so_snd.sb_hiwat, so->so_state));
if (sosendallatonce(so) && (resid > (int)so->so_snd.sb_hiwat))
return (EMSGSIZE);
dontroute = (flags & MSG_DONTROUTE) &&
((so->so_options & SO_DONTROUTE) == 0) &&
(so->so_proto->pr_flags & PR_ATOMIC);
#define snderr(errno) { error = errno; goto release; }
restart:
sblock(&so->so_snd);
do
{
if (so->so_error)
{
error = so->so_error;
so->so_error = 0; /* ??? */
goto release;
}
if (so->so_state & SS_CANTSENDMORE)
snderr(EPIPE);
if ((so->so_state & SS_ISCONNECTED) == 0)
{
if (so->so_proto->pr_flags & PR_CONNREQUIRED)
snderr(ENOTCONN);
if (nam == 0)
snderr(EDESTADDRREQ);
}
if (flags & MSG_OOB)
space = 1024;
else
{
space = (int)sbspace(&so->so_snd);
if ((sosendallatonce(so) && (space < resid)) ||
((resid >= CLBYTES) && (space < CLBYTES) &&
(so->so_snd.sb_cc >= CLBYTES) &&
((so->so_state & SS_NBIO) == 0) &&
((flags & MSG_DONTWAIT) == 0)))
{
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT))
{
if (first)
error = EWOULDBLOCK;
goto release;
}
sbunlock(&so->so_snd);
sbwait(&so->so_snd);
goto restart;
}
}
if ( space <= 0 )
{
/* no space in socket send buffer - see if we can wait */
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT))
{
if (first) /* report first error */
error = EWOULDBLOCK;
goto release;
}
/* If blocking socket, let someone else run */
sbunlock(&so->so_snd);
sbwait(&so->so_snd);
goto restart;
}
while (space > 0)
{
len = resid;
if ( so->so_type == SOCK_STREAM )
//.........这里部分代码省略.........
开发者ID:ECE492W2014G4,项目名称:G4Capstone,代码行数:101,代码来源:socket.c
注:本文中的sbspace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论