sockets: add unix_connect_opts
Add unix_connect_opts(). Does the same as unix_connect(), but uses QemuOpts. unix_connect() is a compatibility wrapper for unix_connect_opts() now and should go away some day. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
7d31544ff6
commit
2af2bf6760
@ -29,6 +29,19 @@
|
|||||||
static int sockets_debug = 0;
|
static int sockets_debug = 0;
|
||||||
static const int on=1, off=0;
|
static const int on=1, off=0;
|
||||||
|
|
||||||
|
/* used temporarely until all users are converted to QemuOpts */
|
||||||
|
QemuOptsList dummy_opts = {
|
||||||
|
.name = "dummy",
|
||||||
|
.head = TAILQ_HEAD_INITIALIZER(dummy_opts.head),
|
||||||
|
.desc = {
|
||||||
|
{
|
||||||
|
.name = "path",
|
||||||
|
.type = QEMU_OPT_STRING,
|
||||||
|
},
|
||||||
|
{ /* end if list */ }
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
static int inet_getport(struct addrinfo *e)
|
static int inet_getport(struct addrinfo *e)
|
||||||
{
|
{
|
||||||
struct sockaddr_in *i4;
|
struct sockaddr_in *i4;
|
||||||
@ -376,11 +389,17 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unix_connect(const char *path)
|
int unix_connect_opts(QemuOpts *opts)
|
||||||
{
|
{
|
||||||
struct sockaddr_un un;
|
struct sockaddr_un un;
|
||||||
|
const char *path = qemu_opt_get(opts, "path");
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
|
if (NULL == path) {
|
||||||
|
fprintf(stderr, "unix connect: no path specified\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
sock = socket(PF_UNIX, SOCK_STREAM, 0);
|
sock = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
perror("socket(unix)");
|
perror("socket(unix)");
|
||||||
@ -400,6 +419,19 @@ int unix_connect(const char *path)
|
|||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* compatibility wrapper */
|
||||||
|
int unix_connect(const char *path)
|
||||||
|
{
|
||||||
|
QemuOpts *opts;
|
||||||
|
int sock;
|
||||||
|
|
||||||
|
opts = qemu_opts_create(&dummy_opts, NULL, 0);
|
||||||
|
qemu_opt_set(opts, "path", path);
|
||||||
|
sock = unix_connect_opts(opts);
|
||||||
|
qemu_opts_del(opts);
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int unix_listen(const char *path, char *ostr, int olen)
|
int unix_listen(const char *path, char *ostr, int olen)
|
||||||
|
@ -29,6 +29,8 @@ int inet_aton(const char *cp, struct in_addr *ia);
|
|||||||
|
|
||||||
#endif /* !_WIN32 */
|
#endif /* !_WIN32 */
|
||||||
|
|
||||||
|
#include "qemu-option.h"
|
||||||
|
|
||||||
/* misc helpers */
|
/* misc helpers */
|
||||||
void socket_set_nonblock(int fd);
|
void socket_set_nonblock(int fd);
|
||||||
int send_all(int fd, const void *buf, int len1);
|
int send_all(int fd, const void *buf, int len1);
|
||||||
@ -39,6 +41,7 @@ int inet_listen(const char *str, char *ostr, int olen,
|
|||||||
int inet_connect(const char *str, int socktype);
|
int inet_connect(const char *str, int socktype);
|
||||||
|
|
||||||
int unix_listen(const char *path, char *ostr, int olen);
|
int unix_listen(const char *path, char *ostr, int olen);
|
||||||
|
int unix_connect_opts(QemuOpts *opts);
|
||||||
int unix_connect(const char *path);
|
int unix_connect(const char *path);
|
||||||
|
|
||||||
/* Old, ipv4 only bits. Don't use for new code. */
|
/* Old, ipv4 only bits. Don't use for new code. */
|
||||||
|
Loading…
Reference in New Issue
Block a user