MCPcopy Create free account
hub / github.com/F-Stack/f-stack / msgbuf_getbytes

Function msgbuf_getbytes

freebsd/kern/subr_msgbuf.c:318–345  ·  view source on GitHub ↗

* Read and mark as read a number of characters from a message buffer. * Returns the number of characters that were placed in `buf'. */

Source from the content-addressed store, hash-verified

316 * Returns the number of characters that were placed in `buf'.
317 */
318int
319msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen)
320{
321 u_int len, pos, wseq;
322
323 mtx_lock_spin(&mbp->msg_lock);
324
325 wseq = mbp->msg_wseq;
326 len = MSGBUF_SEQSUB(mbp, wseq, mbp->msg_rseq);
327 if (len == 0) {
328 mtx_unlock_spin(&mbp->msg_lock);
329 return (0);
330 }
331 if (len > mbp->msg_size) {
332 mbp->msg_rseq = MSGBUF_SEQNORM(mbp, wseq - mbp->msg_size);
333 len = mbp->msg_size;
334 }
335 pos = MSGBUF_SEQ_TO_POS(mbp, mbp->msg_rseq);
336 len = min(len, mbp->msg_size - pos);
337 len = min(len, (u_int)buflen);
338
339 bcopy(&mbp->msg_ptr[pos], buf, len);
340 mbp->msg_rseq = MSGBUF_SEQNORM(mbp, mbp->msg_rseq + len);
341
342 mtx_unlock_spin(&mbp->msg_lock);
343
344 return (len);
345}
346
347/*
348 * Peek at the full contents of a message buffer without marking any

Callers 1

logreadFunction · 0.85

Calls 1

minFunction · 0.85

Tested by

no test coverage detected