Modify net/socket.c to use functions from include/qemu/sockets.h
Subsystems (2)
PATCH 1/1 Modify net/socket.c to use functions from include/qemu/sockets.h
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in net/socket.c with inet_connect()/inet_listen/inet_parse() in include/qemu/sockets.h.
--- net/socket.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
net/socket.c +11 -8
@@ -524,8 +524,9 @@ static int net_socket_listen_init(NetClientState *peer,NetSocketState *s;struct sockaddr_in saddr;int fd, ret; +Error *local_error =NULL ; -if (parse_host_port (&saddr, host_str) <0 ) +if (inet_parse (host_str, &local_error) <0 )return -1 ; fd =qemu_socket (PF_INET ,SOCK_STREAM ,0 );
@@ -543,7 +544,7 @@ static int net_socket_listen_init(NetClientState *peer,closesocket (fd);return -1 ; } - ret =listen (fd,0 ); + ret =inet_listen (host_str,NULL ,256 ,SOCK_STREAM ,0 , &local_error);if (ret <0 ) {perror ("listen" );closesocket (fd);
@@ -568,8 +569,9 @@ static int net_socket_connect_init(NetClientState *peer,NetSocketState *s;int fd, connected, ret;struct sockaddr_in saddr; +Error *local_error =NULL ; -if (parse_host_port (&saddr, host_str) <0 ) +if (inet_parse (host_str, &local_error) <0 )return -1 ; fd =qemu_socket (PF_INET ,SOCK_STREAM ,0 );
@@ -581,7 +583,7 @@ static int net_socket_connect_init(NetClientState *peer, connected =0 ;for (;;) { - ret =connect (fd, (struct sockaddr *)&saddr,sizeof (saddr)); + ret =inet_connect (host_str, &local_error);if (ret <0 ) {if (errno ==EINTR || errno ==EWOULDBLOCK ) {/* continue */
@@ -618,8 +620,8 @@ static int net_socket_mcast_init(NetClientState *peer,int fd;struct sockaddr_in saddr;struct in_addr localaddr, *param_localaddr; - -if (parse_host_port (&saddr, host_str) <0 ) +Error *local_error =NULL ; +if (inet_parse (host_str, &local_error) <0 )return -1 ;if (localaddr_str !=NULL ) {
@@ -656,12 +658,13 @@ static int net_socket_udp_init(NetClientState *peer,NetSocketState *s;int fd, ret;struct sockaddr_in laddr, raddr; +Error *local_error =NULL ; -if (parse_host_port (&laddr, lhost) <0 ) { +if (inet_parse (lhost, &local_error) <0 ) {return -1 ; } -if (parse_host_port (&raddr, rhost) <0 ) { +if (inet_parse (rhost, &local_error) <0 ) {return -1 ; }
Signature · 1 line
1.9.1
Quoted 4 lines · Ashijeet Acharya
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in
net/socket.cwith inet_connect()/inet_listen/inet_parse() ininclude/qemu/sockets.h.
If you're going to re-work this, then I think it'd be better to go straight to using socket_connect() / socket_listen() / socket_parse() which are QAPI based. The inet_* function should eventually be going away once everything is using the QAPI based socket_* functions, so adding more usage of them is not too desirable.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 12 lines · Daniel P. Berrange
Quoted 4 lines · Ashijeet Acharya
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in
net/socket.cwith inet_connect()/inet_listen/inet_parse() ininclude/qemu/sockets.h.If you're going to re-work this, then I think it'd be better to go straight to using
socket_connect()/socket_listen()/socket_parse()which are QAPI based. The inet_* function should eventually be going away once everything is using the QAPI based socket_* functions, so adding more usage of them is not too desirable.
Yeah sure I can do that. Also I was wondering if there is a similar function for bind because the task listed on wiki BiteSized also expects replacement of bind(). So maybe adding/defining socket_bind() in util/qemu-sockets.c and the header include/qemu/sockets.h be helpful.
Thanks!
Ashijeet
Quoted 3 lines
Regards,
Daniel
Quoted 16 lines · Ashi
Quoted 12 lines · Daniel P. Berrange
Quoted 4 lines · Ashijeet Acharya
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in
net/socket.cwith inet_connect()/inet_listen/inet_parse() ininclude/qemu/sockets.h.If you're going to re-work this, then I think it'd be better to go straight to using
socket_connect()/socket_listen()/socket_parse()which are QAPI based. The inet_* function should eventually be going away once everything is using the QAPI based socket_* functions, so adding more usage of them is not too desirable.
Quoted 4 lines
Yeah sure I can do that. Also I was wondering if there is a similar function for bind because the task listed on wiki BiteSized also expects replacement of
bind(). So maybe adding/definingsocket_bind()inutil/qemu-sockets.cand the headerinclude/qemu/sockets.hbe helpful.
bind() is done automatically as part of the socket_listen() function
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 17 lines · Daniel P. Berrange
Quoted 16 lines · Ashi
Quoted 12 lines · Daniel P. Berrange
Quoted 4 lines · Ashijeet Acharya
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in
net/socket.cwith inet_connect()/inet_listen/inet_parse() ininclude/qemu/sockets.h.If you're going to re-work this, then I think it'd be better to go straight to using
socket_connect()/socket_listen()/socket_parse()which are QAPI based. The inet_* function should eventually be going away once everything is using the QAPI based socket_* functions, so adding more usage of them is not too desirable.
Quoted 6 lines
Quoted 4 lines
Yeah sure I can do that. Also I was wondering if there is a similar function for bind because the task listed on wiki BiteSized also expects replacement of
bind(). So maybe adding/definingsocket_bind()inutil/qemu-sockets.cand the headerinclude/qemu/sockets.hbe helpful.
bind()is done automatically as part of thesocket_listen()function
Well, I have completed replacing all the older functions with new QAPI based socket_*() ones. Although I am stuck at a part which uses snprintf() in net_socket_connect_init() function (line no. 605). The inet_ntoa() and ntohs() used in snprintf() are really bugging me as I am not sure how to use them with the new SocketAddress type sockets. The code compiles without snprintf() but I am not sure what effect does it have as a whole to abort snprintf(). I am not sure what to do with that??
Thanks!
Ashijeet
Quoted 4 lines
Regards,
Daniel
Quoted 25 lines · Ashi
Quoted 17 lines · Daniel P. Berrange
Quoted 16 lines · Ashi
Quoted 12 lines · Daniel P. Berrange
Quoted 4 lines · Ashijeet Acharya
From: Ashijeet <[email protected]>
Replaced connect()/listen()/parse_host_port() in
net/socket.cwith inet_connect()/inet_listen/inet_parse() ininclude/qemu/sockets.h.If you're going to re-work this, then I think it'd be better to go straight to using
socket_connect()/socket_listen()/socket_parse()which are QAPI based. The inet_* function should eventually be going away once everything is using the QAPI based socket_* functions, so adding more usage of them is not too desirable.Quoted 6 lines
Quoted 4 lines
Yeah sure I can do that. Also I was wondering if there is a similar function for bind because the task listed on wiki BiteSized also expects replacement of
bind(). So maybe adding/definingsocket_bind()inutil/qemu-sockets.cand the headerinclude/qemu/sockets.hbe helpful.
bind()is done automatically as part of thesocket_listen()function
Quoted 7 lines
Well, I have completed replacing all the older functions with new QAPI based socket_*() ones. Although I am stuck at a part which uses
snprintf()innet_socket_connect_init()function (line no. 605). Theinet_ntoa()andntohs()used insnprintf()are really bugging me as I am not sure how to use them with the new SocketAddress type sockets. The code compiles withoutsnprintf()but I am not sure what effect does it have as a whole to abortsnprintf(). I am not sure what to do with that??
It is hard to answer that without you showing what your code conversion currently looks like...
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|