qemu-sockets.c (9e8f8b1cd8e1b85dc93c367c4745f9944079a37b) | qemu-sockets.c (87ea75d5e135c0527c6a9dbac4317913409f28c7) |
---|---|
1/* 2 * inet and unix socket functions for qemu 3 * 4 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; under version 2 of the License. --- 564 unchanged lines hidden (view full) --- 573{ 574 QemuOpts *opts; 575 char *optstr; 576 int sock = -1; 577 InetSocketAddress *addr; 578 579 addr = inet_parse(str, errp); 580 if (addr != NULL) { | 1/* 2 * inet and unix socket functions for qemu 3 * 4 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; under version 2 of the License. --- 564 unchanged lines hidden (view full) --- 573{ 574 QemuOpts *opts; 575 char *optstr; 576 int sock = -1; 577 InetSocketAddress *addr; 578 579 addr = inet_parse(str, errp); 580 if (addr != NULL) { |
581 opts = qemu_opts_create_nofail(&socket_optslist); | 581 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
582 inet_addr_to_opts(opts, addr); 583 qapi_free_InetSocketAddress(addr); 584 sock = inet_listen_opts(opts, port_offset, errp); 585 if (sock != -1 && ostr) { 586 optstr = strchr(str, ','); 587 if (qemu_opt_get_bool(opts, "ipv6", 0)) { 588 snprintf(ostr, olen, "[%s]:%s%s", 589 qemu_opt_get(opts, "host"), --- 22 unchanged lines hidden (view full) --- 612int inet_connect(const char *str, Error **errp) 613{ 614 QemuOpts *opts; 615 int sock = -1; 616 InetSocketAddress *addr; 617 618 addr = inet_parse(str, errp); 619 if (addr != NULL) { | 582 inet_addr_to_opts(opts, addr); 583 qapi_free_InetSocketAddress(addr); 584 sock = inet_listen_opts(opts, port_offset, errp); 585 if (sock != -1 && ostr) { 586 optstr = strchr(str, ','); 587 if (qemu_opt_get_bool(opts, "ipv6", 0)) { 588 snprintf(ostr, olen, "[%s]:%s%s", 589 qemu_opt_get(opts, "host"), --- 22 unchanged lines hidden (view full) --- 612int inet_connect(const char *str, Error **errp) 613{ 614 QemuOpts *opts; 615 int sock = -1; 616 InetSocketAddress *addr; 617 618 addr = inet_parse(str, errp); 619 if (addr != NULL) { |
620 opts = qemu_opts_create_nofail(&socket_optslist); | 620 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
621 inet_addr_to_opts(opts, addr); 622 qapi_free_InetSocketAddress(addr); 623 sock = inet_connect_opts(opts, errp, NULL, NULL); 624 qemu_opts_del(opts); 625 } 626 return sock; 627} 628 --- 17 unchanged lines hidden (view full) --- 646 QemuOpts *opts; 647 int sock = -1; 648 InetSocketAddress *addr; 649 650 g_assert(callback != NULL); 651 652 addr = inet_parse(str, errp); 653 if (addr != NULL) { | 621 inet_addr_to_opts(opts, addr); 622 qapi_free_InetSocketAddress(addr); 623 sock = inet_connect_opts(opts, errp, NULL, NULL); 624 qemu_opts_del(opts); 625 } 626 return sock; 627} 628 --- 17 unchanged lines hidden (view full) --- 646 QemuOpts *opts; 647 int sock = -1; 648 InetSocketAddress *addr; 649 650 g_assert(callback != NULL); 651 652 addr = inet_parse(str, errp); 653 if (addr != NULL) { |
654 opts = qemu_opts_create_nofail(&socket_optslist); | 654 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
655 inet_addr_to_opts(opts, addr); 656 qapi_free_InetSocketAddress(addr); 657 sock = inet_connect_opts(opts, errp, callback, opaque); 658 qemu_opts_del(opts); 659 } 660 return sock; 661} 662 --- 126 unchanged lines hidden (view full) --- 789 790/* compatibility wrapper */ 791int unix_listen(const char *str, char *ostr, int olen, Error **errp) 792{ 793 QemuOpts *opts; 794 char *path, *optstr; 795 int sock, len; 796 | 655 inet_addr_to_opts(opts, addr); 656 qapi_free_InetSocketAddress(addr); 657 sock = inet_connect_opts(opts, errp, callback, opaque); 658 qemu_opts_del(opts); 659 } 660 return sock; 661} 662 --- 126 unchanged lines hidden (view full) --- 789 790/* compatibility wrapper */ 791int unix_listen(const char *str, char *ostr, int olen, Error **errp) 792{ 793 QemuOpts *opts; 794 char *path, *optstr; 795 int sock, len; 796 |
797 opts = qemu_opts_create_nofail(&socket_optslist); | 797 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
798 799 optstr = strchr(str, ','); 800 if (optstr) { 801 len = optstr - str; 802 if (len) { 803 path = g_malloc(len+1); 804 snprintf(path, len+1, "%.*s", len, str); 805 qemu_opt_set(opts, "path", path); --- 11 unchanged lines hidden (view full) --- 817 return sock; 818} 819 820int unix_connect(const char *path, Error **errp) 821{ 822 QemuOpts *opts; 823 int sock; 824 | 798 799 optstr = strchr(str, ','); 800 if (optstr) { 801 len = optstr - str; 802 if (len) { 803 path = g_malloc(len+1); 804 snprintf(path, len+1, "%.*s", len, str); 805 qemu_opt_set(opts, "path", path); --- 11 unchanged lines hidden (view full) --- 817 return sock; 818} 819 820int unix_connect(const char *path, Error **errp) 821{ 822 QemuOpts *opts; 823 int sock; 824 |
825 opts = qemu_opts_create_nofail(&socket_optslist); | 825 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
826 qemu_opt_set(opts, "path", path); 827 sock = unix_connect_opts(opts, errp, NULL, NULL); 828 qemu_opts_del(opts); 829 return sock; 830} 831 832 833int unix_nonblocking_connect(const char *path, 834 NonBlockingConnectHandler *callback, 835 void *opaque, Error **errp) 836{ 837 QemuOpts *opts; 838 int sock = -1; 839 840 g_assert(callback != NULL); 841 | 826 qemu_opt_set(opts, "path", path); 827 sock = unix_connect_opts(opts, errp, NULL, NULL); 828 qemu_opts_del(opts); 829 return sock; 830} 831 832 833int unix_nonblocking_connect(const char *path, 834 NonBlockingConnectHandler *callback, 835 void *opaque, Error **errp) 836{ 837 QemuOpts *opts; 838 int sock = -1; 839 840 g_assert(callback != NULL); 841 |
842 opts = qemu_opts_create_nofail(&socket_optslist); | 842 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
843 qemu_opt_set(opts, "path", path); 844 sock = unix_connect_opts(opts, errp, callback, opaque); 845 qemu_opts_del(opts); 846 return sock; 847} 848 849SocketAddress *socket_parse(const char *str, Error **errp) 850{ --- 33 unchanged lines hidden (view full) --- 884} 885 886int socket_connect(SocketAddress *addr, Error **errp, 887 NonBlockingConnectHandler *callback, void *opaque) 888{ 889 QemuOpts *opts; 890 int fd; 891 | 843 qemu_opt_set(opts, "path", path); 844 sock = unix_connect_opts(opts, errp, callback, opaque); 845 qemu_opts_del(opts); 846 return sock; 847} 848 849SocketAddress *socket_parse(const char *str, Error **errp) 850{ --- 33 unchanged lines hidden (view full) --- 884} 885 886int socket_connect(SocketAddress *addr, Error **errp, 887 NonBlockingConnectHandler *callback, void *opaque) 888{ 889 QemuOpts *opts; 890 int fd; 891 |
892 opts = qemu_opts_create_nofail(&socket_optslist); | 892 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
893 switch (addr->kind) { 894 case SOCKET_ADDRESS_KIND_INET: 895 inet_addr_to_opts(opts, addr->inet); 896 fd = inet_connect_opts(opts, errp, callback, opaque); 897 break; 898 899 case SOCKET_ADDRESS_KIND_UNIX: 900 qemu_opt_set(opts, "path", addr->q_unix->path); --- 15 unchanged lines hidden (view full) --- 916 return fd; 917} 918 919int socket_listen(SocketAddress *addr, Error **errp) 920{ 921 QemuOpts *opts; 922 int fd; 923 | 893 switch (addr->kind) { 894 case SOCKET_ADDRESS_KIND_INET: 895 inet_addr_to_opts(opts, addr->inet); 896 fd = inet_connect_opts(opts, errp, callback, opaque); 897 break; 898 899 case SOCKET_ADDRESS_KIND_UNIX: 900 qemu_opt_set(opts, "path", addr->q_unix->path); --- 15 unchanged lines hidden (view full) --- 916 return fd; 917} 918 919int socket_listen(SocketAddress *addr, Error **errp) 920{ 921 QemuOpts *opts; 922 int fd; 923 |
924 opts = qemu_opts_create_nofail(&socket_optslist); | 924 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
925 switch (addr->kind) { 926 case SOCKET_ADDRESS_KIND_INET: 927 inet_addr_to_opts(opts, addr->inet); 928 fd = inet_listen_opts(opts, 0, errp); 929 break; 930 931 case SOCKET_ADDRESS_KIND_UNIX: 932 qemu_opt_set(opts, "path", addr->q_unix->path); --- 11 unchanged lines hidden (view full) --- 944 return fd; 945} 946 947int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) 948{ 949 QemuOpts *opts; 950 int fd; 951 | 925 switch (addr->kind) { 926 case SOCKET_ADDRESS_KIND_INET: 927 inet_addr_to_opts(opts, addr->inet); 928 fd = inet_listen_opts(opts, 0, errp); 929 break; 930 931 case SOCKET_ADDRESS_KIND_UNIX: 932 qemu_opt_set(opts, "path", addr->q_unix->path); --- 11 unchanged lines hidden (view full) --- 944 return fd; 945} 946 947int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) 948{ 949 QemuOpts *opts; 950 int fd; 951 |
952 opts = qemu_opts_create_nofail(&socket_optslist); | 952 opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); |
953 switch (remote->kind) { 954 case SOCKET_ADDRESS_KIND_INET: 955 qemu_opt_set(opts, "host", remote->inet->host); 956 qemu_opt_set(opts, "port", remote->inet->port); 957 if (local) { 958 qemu_opt_set(opts, "localaddr", local->inet->host); 959 qemu_opt_set(opts, "localport", local->inet->port); 960 } 961 fd = inet_dgram_opts(opts, errp); 962 break; 963 964 default: 965 error_setg(errp, "socket type unsupported for datagram"); 966 fd = -1; 967 } 968 qemu_opts_del(opts); 969 return fd; 970} | 953 switch (remote->kind) { 954 case SOCKET_ADDRESS_KIND_INET: 955 qemu_opt_set(opts, "host", remote->inet->host); 956 qemu_opt_set(opts, "port", remote->inet->port); 957 if (local) { 958 qemu_opt_set(opts, "localaddr", local->inet->host); 959 qemu_opt_set(opts, "localport", local->inet->port); 960 } 961 fd = inet_dgram_opts(opts, errp); 962 break; 963 964 default: 965 error_setg(errp, "socket type unsupported for datagram"); 966 fd = -1; 967 } 968 qemu_opts_del(opts); 969 return fd; 970} |