Make soreceive(MSG_DONTWAIT) nonblocking. If MSG_DONTWAIT is passed into

soreceive(), then pass in M_DONTWAIT to m_copym(). Also fix up error
handling for the case where m_copym() returns failure.

Submitted by:	Mohan Srinivasan mohans at yahoo-inc dot com
Reviewed by:	rwatson
This commit is contained in:
ps 2004-11-29 23:09:07 +00:00
parent 2b85447398
commit 9ed5c9cd2b

View File

@ -1291,9 +1291,27 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
moff += len;
else {
if (mp != NULL) {
SOCKBUF_UNLOCK(&so->so_rcv);
*mp = m_copym(m, 0, len, M_TRYWAIT);
SOCKBUF_LOCK(&so->so_rcv);
int copy_flag;
if (flags & MSG_DONTWAIT)
copy_flag = M_DONTWAIT;
else
copy_flag = M_TRYWAIT;
if (copy_flag == M_TRYWAIT)
SOCKBUF_UNLOCK(&so->so_rcv);
*mp = m_copym(m, 0, len, copy_flag);
if (copy_flag == M_TRYWAIT)
SOCKBUF_LOCK(&so->so_rcv);
if (*mp == NULL) {
/*
* m_copym() couldn't allocate an mbuf.
* Adjust uio_resid back (it was adjusted
* down by len bytes, which we didn't end
* up "copying" over).
*/
uio->uio_resid += len;
break;
}
}
m->m_data += len;
m->m_len -= len;