Re: [Qemu-devel] [PATCH 2/4] net/socket: allow ipv6 for net_socket_listen_init and socket_connect_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 10.02.2012 07:27, schrieb Amos Kong:
> Remove use of parse_host_port.
> More SO_SOCKADDR changes.
> 
> Signed-off-by: Juan Quintela <quintela@xxxxxxxxxx>
> Signed-off-by: Amos Kong <akong@xxxxxxxxxx>
> ---
>  net/socket.c |   60 +++++++++++-----------------------------------------------
>  1 files changed, 11 insertions(+), 49 deletions(-)
> 
> diff --git a/net/socket.c b/net/socket.c
> index d4c2002..439a69c 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -403,29 +403,13 @@ static int net_socket_listen_init(VLANState *vlan,
>                                    const char *host_str)
>  {
>      NetSocketListenState *s;
> -    int fd, val, ret;
> -    struct sockaddr_in saddr;
> -
> -    if (parse_host_port(&saddr, host_str) < 0)
> -        return -1;
> +    int fd, ret;
>  
>      s = g_malloc0(sizeof(NetSocketListenState));
>  
> -    fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
> -    if (fd < 0) {
> -        perror("socket");
> -        g_free(s);
> -        return -1;
> -    }
> -    socket_set_nonblock(fd);
> -
> -    /* allow fast reuse */
> -    val = 1;
> -    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
> -
> -    ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
> +    ret = tcp_server_start(host_str, &fd);
>      if (ret < 0) {
> -        perror("bind");
> +        fprintf(stderr, "tcp_server_start: %s\n", strerror(ret));

error_report, and it should be strerror(-ret).

>          g_free(s);
>          closesocket(fd);
>          return -1;
> @@ -451,41 +435,19 @@ static int net_socket_connect_init(VLANState *vlan,
>                                     const char *host_str)
>  {
>      NetSocketState *s;
> -    int fd, connected, ret, err;
> +    int fd, connected, ret;
>      struct sockaddr_in saddr;
>  
> -    if (parse_host_port(&saddr, host_str) < 0)
> -        return -1;
> -
> -    fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
> -    if (fd < 0) {
> -        perror("socket");
> +    ret = tcp_client_start(host_str, &fd);
> +    if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
> +        connected = 0;
> +    } else if (ret < 0) {
> +        closesocket(fd);

There is no open fd in this case. The only time that fd != -1 and ret <
0 is for -EINPROGRESS and -EWOULDBLOCK.

>          return -1;
> +    } else {
> +        connected = 1;
>      }
> -    socket_set_nonblock(fd);
>  
> -    connected = 0;
> -    for(;;) {
> -        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
> -        if (ret < 0) {
> -            err = socket_error();
> -            if (err == EINTR || err == EWOULDBLOCK) {
> -            } else if (err == EINPROGRESS) {
> -                break;
> -#ifdef _WIN32
> -            } else if (err == WSAEALREADY || err == WSAEINVAL) {
> -                break;
> -#endif

This part is lost without replacement?

> -            } else {
> -                perror("connect");
> -                closesocket(fd);

tcp_client_start uses close() instead of closesocket() in error case,
should probably be changed.

Kevin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux