libssh2_channel_read_ex(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

libssh2_channel_read_ex β€” bestie, this is the one that reads data from a channel stream πŸ’–

(and yes, it lives in the libssh2 manual, section 3, iykyk 🫢)


🌸 SYNOPSIS 🌸

okay so first you gotta include the header, obviously:

#include <libssh2.h>

ssize_t
libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id,
                        char *buf, size_t buflen);

ssize_t
libssh2_channel_read(LIBSSH2_CHANNEL *channel,
                     char *buf, size_t buflen);

ssize_t
libssh2_channel_read_stderr(LIBSSH2_CHANNEL *channel,
                            char *buf, size_t buflen);

look at those three. iconic. the whole squad πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the vibe here is: you're attempting to read data from an active channel stream. that's the whole job. that's the assignment and she ate πŸ”₯

every single channel stream comes with one standard I/O substream (that's stream_id == 0, the default main-character one πŸ‘‘), and she may also have up to 2^32 extended data streams, each one identified by whichever stream_id you pick. like, 2^32. that's so many. not me being obsessed with the scale of it 😭

and the SSH2 protocol? rn it defines stream ID 1 to be the stderr substream. so that's the one you know about for sure.

here's the cast of characters, one by one:

  • channel β€” the active channel stream you're reading from. your girl. your connection. 🫢
  • stream_id β€” the substream ID number, like 0 or SSH_EXTENDED_DATA_STDERR ✨
  • buf β€” a pointer to the storage buffer where the data gets read into πŸ“₯
  • buflen β€” the size of that buf storage. know her limits, respect her limits πŸ’–

and heads up bestie: libssh2_channel_read(3) and libssh2_channel_read_stderr(3) are macros. not full separate functions. macros. don't be weird about it 🌸


πŸ’– RETURN VALUE πŸ’–

she returns the actual number of bytes read, or a negative number on failure. no cap.

and when she would otherwise block? she hits you with LIBSSH2_ERROR_EAGAIN. and listen β€” LIBSSH2_ERROR_EAGAIN is technically a negative number, but it's not really a failure per se. it's giving "not right now, try again later" energy, not "everything is on fire" energy 🧚

also like. a return value of zero (0) can totally be a legitimate value. it just means no payload data was read. that's it. it is not an error. do NOT panic. do not text the group chat. she's fine πŸ’…

πŸ’€ ERRORS πŸ’€

  • LIBSSH2_ERROR_SOCKET_SEND β€” unable to send data on socket 😭
  • LIBSSH2_ERROR_CHANNEL_CLOSED β€” the channel has been closed. she's gone. closed. doors shut. πŸ™ˆ

🌈 SEE ALSO 🌈


this page is from libssh2 version 0.15, dated 1 Jun 2007 β€” yeah she's vintage but she still slays, periodt πŸ’…βœ¨πŸŽ€πŸ¦‹