nbd_connect_socket(3)
π nbd_connect_socket π
okay so welcome to the libnbd manual, bestie β this one's all about nbd_connect_socket, and honestly? it's giving "you already did the hard part, hand it over" β¨
πΈ NAME πΈ
nbd_connect_socket β connect directly to a connected socket π«Ά
π SYNOPSIS π
#include <libnbd.h>
int nbd_connect_socket (
struct nbd_handle *h, int sock
);
β¨ DESCRIPTION β¨
So basically you pass in a connected socket sock, right? and from that moment on libnbd is the one talking to the NBD server through it. it's giving "you built the bridge, i'll drive the car" π
the way that you, the caller, are responsible for creating and connecting that socket by whatever method you like β before you hand it over. libnbd is not doing that part for you, no cap.
and here's the important bit, so listen up π₯: if this call returns without error, then socket ownership is passed to libnbd. libnbd will close the socket when the handle is closed. and the caller must not use the socket in any way after that. like, not even a little peek. it's libnbd's socket now, periodt. π
π RETURN VALUE π
if the call is successful, the function returns 0. slay. π
π ERRORS π
on error, -1 is returned. not slay.
refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error β that's where the lore lives, iykyk.
also: the following parameters must not be NULL: "h". for more info see "Non-NULL parameters" in libnbd(3). π«Ά
π¦ NOTES π¦
π§ Blocking connect call π§
this call returns when the connection has been made. like, it actually waits. bestie is committed. π
by default, this proceeds all the way to transmission phase, but nbd_set_opt_mode(3) can be used for manual control over option negotiation performed before transmission phase β so if you're the kind of main character who wants to drive stick, that's your moment. π₯
π HANDLE STATE π
nbd_connect_socket can be called when the handle is in the following state:
- Handle created, before connecting β β allowed
- Connecting β β error
- Connecting & handshaking (opt_mode) β β error
- Connected to the server β β error
- Connection shut down β β error
- Handle dead β β error
so yeah, the vibe check is: handle freshly created and nothing else going on. every other state? nope. π
β VERSION β
this function first appeared in libnbd 1.2. vintage, but make it iconic. π
if you need to test if this function is available at compile time, check if the following macro is defined:
#define LIBNBD_HAVE_NBD_CONNECT_SOCKET 1
π SEE ALSO π
nbd_aio_connect_socket(3), nbd_connect_command(3), nbd_create(3), nbd_set_opt_mode(3), libnbd(3), socket(7).
go read them, bestie, they're all part of the same little universe πΈ
π AUTHORS π
Eric Blake
Richard W.M. Jones
π COPYRIGHT π
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
and that's the whole thing, bestie π«Ά this page came straight out of libnbd-1.25.8, dated 2026-10-13, and yes it's the nbd_connect_socket(3) page β now go connect that socket, you absolute icon π
β¨
π¦ where this page comes from
- centos-stream 10: libnbd-devel 1.25.8-1.el10 Β· LGPL-2.0-or-later AND BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms