MONGOC_STREAM_READ(3)

🌸 MONGOC_STREAM_READ(3) 🌸

okay so bestie, this one's from libmongoc and it's genuinely one of the more lowkey-important little functions in the whole stream saga. it's giving "tiny signature, big feelings." let's get into it πŸ’…


✨ SYNOPSIS ✨

ssize_t
mongoc_stream_read (mongoc_stream_t *stream,
                    void *buf,
                    size_t count,
                    size_t min_bytes,
                    int32_t timeout_msec);

look at her. five arguments. no notes. πŸŽ€


πŸ’– PARAMETERS πŸ’–

  • stream β€” a mongoc_stream_t. the stream you're reading from, obviously. she's the main character here.
  • buf β€” the buffer to read into. like, the bucket you're dumping the bytes into πŸͺ£
  • count β€” the number of bytes to read. how much you want, ideally.
  • min_bytes β€” the minimum number of bytes to read, or else indicate failure. this is the "i'll accept less than count, but if you give me less than this i'm calling it a fail" number.
  • timeout_msec β€” the number of milliseconds to wait before failure. a timeout of 0 will not block (fr fr, zero blocking). if it's negative, use the default timeout.

the mongoc_stream_read() function shall perform a read from a mongoc_stream_t. it's modeled on the API and semantics of read(), though the parameters map only loosely β€” like, they're cousins, not twins. iykyk 🌈

⚠️ WARNING: the "default timeout" indicated by a negative value is both unspecified and unrelated to the documented default values for *TimeoutMS URI options. so do not go assuming they're the same thing, bestie, they are not. to specify a default timeout value for a *TimeoutMS URI option, use the MONGOC_DEFAULT_* constants defined in mongoc-client.h. that's the icon right there πŸ‘‘

πŸ¦‹ RETURNS πŸ¦‹

the mongoc_stream_read() function returns the number of bytes read on success. slay πŸ’«

it returns >= 0 and < min_bytes when end-of-file is encountered β€” yes, that's a subtle little in-between zone, clock it β€” and -1 on failure. and when it fails, errno is set upon failure. so check your errno, she's talking to you 😭


πŸ‘€ SEE ALSO πŸ‘€

  • mongoc_stream_readv()
  • mongoc_stream_write()
  • mongoc_stream_writev()

the whole friend group. readv and writev are the vectorized girlies, write is the classic. go say hi 🫢


πŸŽ€ AUTHOR πŸŽ€

MongoDB, Inc


2009-present, MongoDB, Inc.


and that's the whole page, no cap. shoutout to libmongoc 2.5.6, dated Oct 09, 2026 β€” like, she's documented, she's timestamped, she ate and left no crumbs πŸ’œβœ¨ go read some bytes bestie πŸ“

πŸ“¦ where this page comes from