-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sock_resolve_one #357
sock_resolve_one #357
Conversation
libcperciva/util/sock.c
Outdated
warn0("Using the first of multiple addresses found for %s", | ||
addr); | ||
|
||
/* Allocate a structure. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err... we have sock_addr_dup
if you want to do it that way. But why not just free the bits we don't want?
sa = sas[0];
for (p = &sas[1]; *p != NULL; p++)
sock_addr_free(*p);
free(sas);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I never noticed sock_util.h
.
I agree that avoiding the malloc is a cleaner solution.
@@ -275,17 +275,13 @@ main(int argc, char * argv[]) | |||
} | |||
|
|||
/* Resolve source address. */ | |||
while ((sas_s = sock_resolve(opt_s)) == NULL) { | |||
while ((sa_s = sock_resolve_one(opt_s)) == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the behaviour from "error out if there are no addresses" to "keep looping forever".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not following. I completely believe that I screwed something up, and/or we need to pass an extra argument to sock_resolve_one
to handle this case elegantly, but I'm not seeing it.
With git master,
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F -D
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
^C
(^C indicates me manually pressing ctrl-C, of course)
With this PR,
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error resolving socket address: 257.0.0.1:8001
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F -D
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
^C
Granted, the double error message in the first case isn't ideal. But the "loop / no loop" behaviour looks the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was thinking of the case where we successfully get zero addresses. (i.e. sock_resolve
returns sas != NULL
but sas[0] == NULL
.)
But I'm not even sure that's possible, so let's not worry about that case.
Change looks good, please rebase. |
7d9e4bc
to
7c5c5af
Compare
Ready for merge. |
No description provided.