On 09/13/2012 03:44 PM, Markus Armbruster wrote:
> Orit Wasserman <owass...@redhat.com> writes:
>
>> No need to add non blocking parameters to the blocking inet_connect
>>
>> Signed-off-by: Orit Wasserman <owass...@redhat.com>
>> ---
>> migration-tcp.c | 2 +-
>> nbd.c | 2 +-
>> qemu-sockets.c | 24 ++++++++++++++++++++----
>> qemu_socket.h | 4 +++-
>> ui/vnc.c | 2 +-
>> 5 files changed, 26 insertions(+), 8 deletions(-)
>>
>> diff --git a/migration-tcp.c b/migration-tcp.c
>> index ac891c3..7f6ad98 100644
>> --- a/migration-tcp.c
>> +++ b/migration-tcp.c
>> @@ -88,7 +88,7 @@ int tcp_start_outgoing_migration(MigrationState *s, const
>> char *host_port,
>> s->write = socket_write;
>> s->close = tcp_close;
>>
>> - s->fd = inet_connect(host_port, false, &in_progress, errp);
>> + s->fd = inet_nonblocking_connect(host_port, &in_progress, errp);
>> if (error_is_set(errp)) {
>> migrate_fd_error(s);
>> return -1;
>> diff --git a/nbd.c b/nbd.c
>> index 0dd60c5..206f75c 100644
>> --- a/nbd.c
>> +++ b/nbd.c
>> @@ -162,7 +162,7 @@ int tcp_socket_outgoing(const char *address, uint16_t
>> port)
>>
>> int tcp_socket_outgoing_spec(const char *address_and_port)
>> {
>> - return inet_connect(address_and_port, true, NULL, NULL);
>> + return inet_connect(address_and_port, NULL);
>> }
>>
>> int tcp_socket_incoming(const char *address, uint16_t port)
>> diff --git a/qemu-sockets.c b/qemu-sockets.c
>> index 68e4d30..4f5eca8 100644
>> --- a/qemu-sockets.c
>> +++ b/qemu-sockets.c
>> @@ -518,16 +518,32 @@ int inet_listen(const char *str, char *ostr, int olen,
>> return sock;
>> }
>>
>> -int inet_connect(const char *str, bool block, bool *in_progress, Error
>> **errp)
>> +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) {
>> - if (block) {
>> - qemu_opt_set(opts, "block", "on");
>> - }
>> + qemu_opt_set(opts, "block", "on");
>> + sock = inet_connect_opts(opts, NULL, errp);
>
> Let's go one step further: make inet_connect_opts() take a bool block
> argument, and drop the stupid QemuOpt "block". That way, opts are again
> for user options only.
Very good idea !
>
>> + } else {
>> + error_set(errp, QERR_SOCKET_CREATE_FAILED);
>> + }
>> + qemu_opts_del(opts);
>> + return sock;
>> +}
>> +
>> +
>> +int inet_nonblocking_connect(const char *str, bool *in_progress,
>> + Error **errp)
>> +{
>> + QemuOpts *opts;
>> + int sock = -1;
>> +
>> + opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
>> + if (inet_parse(opts, str) == 0) {
>> + qemu_opt_set(opts, "block", "off");
>> sock = inet_connect_opts(opts, in_progress, errp);
>> } else {
>> error_set(errp, QERR_SOCKET_CREATE_FAILED);
> [...]
>