---
name: "mongoc_stream_read"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_stream_read"
---

# mongoc\_stream\_read(3)

## SYNOPSIS

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

## PARAMETERS

- •

  **stream**: A *mongoc\_stream\_t*.

- •

  **buf**: The buffer to read into.

- •

  **count**: The number of bytes to read.

- •

  **min\_bytes**: The minimum number of bytes to read, or else indicate failure.

- •

  **timeout\_msec**: The number of milliseconds to wait before failure, a timeout of 0 will not block. If 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.

**WARNING:**

The "default timeout" indicated by a negative value is both unspecified and unrelated to the documented default values for **\*TimeoutMS** URI options. To specify a default timeout value for a **\*TimeoutMS** URI option, use the **MONGOC\_DEFAULT\_\*** constants defined in **mongoc-client.h**.

## RETURNS

The *mongoc\_stream\_read()* function returns the number of bytes read on success. It returns **\>= 0** and **\< min\_bytes** when end-of-file is encountered and **-1** on failure. **errno** is set upon failure.

**SEE ALSO:**

```
mongoc_stream_readv()
```

```
mongoc_stream_write()
```

```
mongoc_stream_writev()
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
