nbd_aio_connect(3)

πŸ’… nbd_aio_connect β€” connect to the NBD server

okay so bestie, welcome to nbd_aio_connect(3), straight out of the libnbd manual (section 3, obviously πŸ’–). this one's literally the "start talking to the server, but make it async" function and it's kind of a big deal.


✨ NAME ✨

nbd_aio_connect β€” connect to the NBD server 🫢


🌸 SYNOPSIS 🌸

#include <libnbd.h>

int nbd_aio_connect (
      struct nbd_handle *h, const struct sockaddr *addr,
      socklen_t addrlen
    );

like, that's it. that's the whole vibe check. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is where you begin connecting to the NBD server β€” no cap. the addr and addrlen parameters are the ones that specify the address of the socket you're connecting to. that's the assignment, that's the whole thing, slay. ✨


πŸ’œ RETURN VALUE πŸ’œ

if the call is successful, the function returns 0. iconic behavior honestly.


πŸ’€ ERRORS πŸ’€

on error, -1 is returned. 😭

refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error β€” that's where the lore lives.

also, these parameters must not be NULL: h, addr. like, don't even try it. for more info see "Non-NULL parameters" in libnbd(3).


πŸŽ€ NOTES πŸŽ€

🧚 Asynchronous connect call

you can check if the connection attempt is still underway by calling nbd_aio_is_connecting(3). multitasking queen behavior fr fr.

if nbd_set_opt_mode(3) is enabled, the connection is ready for manual option negotiation once nbd_aio_is_negotiating(3) returns true. otherwise, the connection attempt will include the NBD handshake, and is ready for use once nbd_aio_is_ready(3) returns true. either way, you're gonna know. πŸ‘‘


🩷 HANDLE STATE 🩷

nbd_aio_connect can be called when the handle is in the following state:

  • Handle created, before connecting β€” βœ… allowed (this is your moment bestie)
  • Connecting β€” ❌ error
  • Connecting & handshaking (opt_mode) β€” ❌ error
  • Connected to the server β€” ❌ error
  • Connection shut down β€” ❌ error
  • Handle dead β€” ❌ error

so yeah, only that first one. everything else is a no. πŸ™ˆ


⭐ VERSION ⭐

this function first appeared in libnbd 1.0. vintage. πŸŽ€

if you need to test if this function is available at compile time, check if the following macro is defined:

#define LIBNBD_HAVE_NBD_AIO_CONNECT 1

🌈 SEE ALSO 🌈

nbd_aio_is_connecting(3), nbd_aio_is_negotiating(3), nbd_aio_is_ready(3), nbd_create(3), nbd_set_opt_mode(3), libnbd(3).

the whole friend group honestly 🫢


πŸ‘‘ AUTHORS πŸ‘‘

Eric Blake

Richard W.M. Jones


Copyright Red Hat


πŸ’– LICENSE πŸ’–

this library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

this library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU Lesser General Public License for more details.

you should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


ok that's the whole page, no notes. go connect to that server bestie, ily πŸ’…βœ¨

and finally β€” this gorgeous little page is libnbd-1.25.8, dated 2026-10-13, and it's the nbd_aio_connect(3) page. mwah. πŸ“πŸ§šπŸ’œ

πŸ“¦ where this page comes from