int socket_connect(SocketAddress *addr, Error **errp, NonBlockingConnectHandler *callback, void *opaque) { QemuOpts *opts; int fd; opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); switch (addr->kind) { case SOCKET_ADDRESS_KIND_INET: inet_addr_to_opts(opts, addr->inet); fd = inet_connect_opts(opts, errp, callback, opaque); break; case SOCKET_ADDRESS_KIND_UNIX: qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort); fd = unix_connect_opts(opts, errp, callback, opaque); break; case SOCKET_ADDRESS_KIND_FD: fd = monitor_get_fd(cur_mon, addr->fd->str, errp); if (fd >= 0 && callback) { qemu_set_nonblock(fd); callback(fd, NULL, opaque); } break; default: abort(); } qemu_opts_del(opts); return fd; }
int inet_connect(const char *str, int socktype) { QemuOpts *opts; int sock = -1; opts = qemu_opts_create(&dummy_opts, NULL, 0); if (inet_parse(opts, str) == 0) sock = inet_connect_opts(opts); qemu_opts_del(opts); return sock; }
/** * Create a blocking socket and connect it to an address. * * @str: address string * @errp: set in case of an error * * Returns -1 in case of error, file descriptor on success **/ int inet_connect(const char *str, Error **errp) { QemuOpts *opts; int sock = -1; opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL); if (inet_parse(opts, str) == 0) { sock = inet_connect_opts(opts, errp, NULL, NULL); } else { error_set(errp, QERR_SOCKET_CREATE_FAILED); } qemu_opts_del(opts); return sock; }
/** * Create a blocking socket and connect it to an address. * * @str: address string * @errp: set in case of an error * * Returns -1 in case of error, file descriptor on success **/ int inet_connect(const char *str, Error **errp) { QemuOpts *opts; int sock = -1; InetSocketAddress *addr; addr = inet_parse(str, errp); if (addr != NULL) { opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); inet_addr_to_opts(opts, addr); qapi_free_InetSocketAddress(addr); sock = inet_connect_opts(opts, errp, NULL, NULL); qemu_opts_del(opts); } return sock; }
/** * Create a non-blocking socket and connect it to an address. * Calls the callback function with fd in case of success or -1 in case of * error. * * @str: address string * @callback: callback function that is called when connect completes, * cannot be NULL. * @opaque: opaque for callback function * @errp: set in case of an error * * Returns: -1 on immediate error, file descriptor on success. **/ int inet_nonblocking_connect(const char *str, NonBlockingConnectHandler *callback, void *opaque, Error **errp) { QemuOpts *opts; int sock = -1; g_assert(callback != NULL); opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL); if (inet_parse(opts, str) == 0) { sock = inet_connect_opts(opts, errp, callback, opaque); } else { error_set(errp, QERR_SOCKET_CREATE_FAILED); } qemu_opts_del(opts); return sock; }
/** * Create a non-blocking socket and connect it to an address. * Calls the callback function with fd in case of success or -1 in case of * error. * * @str: address string * @callback: callback function that is called when connect completes, * cannot be NULL. * @opaque: opaque for callback function * @errp: set in case of an error * * Returns: -1 on immediate error, file descriptor on success. **/ int inet_nonblocking_connect(const char *str, NonBlockingConnectHandler *callback, void *opaque, Error **errp) { QemuOpts *opts; int sock = -1; InetSocketAddress *addr; g_assert(callback != NULL); addr = inet_parse(str, errp); if (addr != NULL) { opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); inet_addr_to_opts(opts, addr); qapi_free_InetSocketAddress(addr); sock = inet_connect_opts(opts, errp, callback, opaque); qemu_opts_del(opts); } return sock; }