* Fixes for OpenBSD
@ 2011-05-05 18:18 Jeremy Evans
2011-05-05 18:45 ` Eric Wong
2011-05-05 19:35 ` Eric Wong
0 siblings, 2 replies; 5+ messages in thread
From: Jeremy Evans @ 2011-05-05 18:18 UTC (permalink / raw)
To: kgio
I'm not sure if these issues are specific to OpenBSD or not, but they
are required on OpenBSD.
With these two patches, kgio-2.3.3 passes the included tests on OpenBSD
except for one failure:
1) Failure:
test_wait_writable_set(TestKgioTcpConnect) [test/test_tcp_connect.rb:69]:
<"waited"> expected but was
<nil>.
Hope this helps,
Jeremy
Fix kgio_peek by adding an empty kgio_autopush_recv
if !KGIO_NOPUSH.
--- ext/kgio/autopush.c.orig Thu May 5 11:02:08 2011
+++ ext/kgio/autopush.c Thu May 5 11:02:12 2011
@@ -242,6 +242,7 @@ static void push_pending_data(VALUE io)
rb_sys_fail("setsockopt(TCP_CORK/TCP_NOPUSH, 1)");
}
#else /* !KGIO_NOPUSH */
+void kgio_autopush_recv(VALUE io){}
void init_kgio_autopush(void)
{
}
getaddrinfo gives an error if you use AF_UNSPEC as the ai_family,
the man page says PF_UNSPEC should be used. And other entries
in hints need to be 0 or NULL.
--- ext/kgio/connect.c.orig Wed Dec 31 16:00:00 1969
+++ ext/kgio/connect.c Thu May 5 10:47:10 2011
@@ -69,7 +69,8 @@ static VALUE tcp_connect(VALUE klass, VALUE ip, VALUE
rc = snprintf(ipport, sizeof(ipport), "%u", uport);
if (rc >= (int)sizeof(ipport) || rc <= 0)
rb_raise(rb_eArgError, "invalid TCP port: %u", uport);
- hints.ai_family = AF_UNSPEC;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
/* disallow non-deterministic DNS lookups */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Fixes for OpenBSD
2011-05-05 18:18 Fixes for OpenBSD Jeremy Evans
@ 2011-05-05 18:45 ` Eric Wong
2011-05-05 19:29 ` Jeremy Evans
2011-05-05 19:35 ` Eric Wong
1 sibling, 1 reply; 5+ messages in thread
From: Eric Wong @ 2011-05-05 18:45 UTC (permalink / raw)
To: kgio
Jeremy Evans <code@jeremyevans.net> wrote:
<snip> other changes look fine
> getaddrinfo gives an error if you use AF_UNSPEC as the ai_family,
> the man page says PF_UNSPEC should be used. And other entries
> in hints need to be 0 or NULL.
I'm not sure why OpenBSD differs from POSIX here:
http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
Even though PF_UNSPEC == AF_UNSPEC in most systems, I'd rather go with
the following patch and single out OpenBSD (and maybe other *BSDs) since
"AF_" (address family) makes more sense than "PF_" (protocol family):
diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c
index 3b40054..e4ee9fb 100644
--- a/ext/kgio/connect.c
+++ b/ext/kgio/connect.c
@@ -1,6 +1,21 @@
#include "kgio.h"
#include "sock_for_fd.h"
+/*
+ * OpenBSD getaddrinfo() requires PF_UNSPEC, but POSIX (and Linux) docs
+ * say AF_UNSPEC. AF_UNSPEC is typically PF_UNSPEC anyways, but apparently
+ * OpenBSD differs.
+ *
+ * http://www.openbsd.org/cgi-bin/man.cgi?query=getaddrinfo&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
+ * http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
+ */
+#if defined(__OpenBSD__)
+# if defined(AF_UNSPEC)
+# undef AF_UNSPEC
+# endif
+# define AF_UNSPEC PF_UNSPEC
+#endif
+
static void close_fail(int fd, const char *msg)
{
int saved_errno = errno;
@@ -69,6 +84,7 @@ static VALUE tcp_connect(VALUE klass, VALUE ip, VALUE port, int io_wait)
rc = snprintf(ipport, sizeof(ipport), "%u", uport);
if (rc >= (int)sizeof(ipport) || rc <= 0)
rb_raise(rb_eArgError, "invalid TCP port: %u", uport);
+ memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
--
Eric Wong
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Fixes for OpenBSD
2011-05-05 18:45 ` Eric Wong
@ 2011-05-05 19:29 ` Jeremy Evans
2011-05-05 19:33 ` Eric Wong
0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Evans @ 2011-05-05 19:29 UTC (permalink / raw)
To: kgio
> I'm not sure why OpenBSD differs from POSIX here:
> http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
>
> Even though PF_UNSPEC == AF_UNSPEC in most systems, I'd rather go with
> the following patch and single out OpenBSD (and maybe other *BSDs) since
> "AF_" (address family) makes more sense than "PF_" (protocol family):
It looks like the AF_UNSPEC -> PF_UNSPEC is not necessary, they must be
defined to the same thing. Why the OpenBSD man page recommends
PF_UNSPEC, I'm not sure. It looks like the memset was the necessary
fix.
Thanks,
Jeremy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Fixes for OpenBSD
2011-05-05 19:29 ` Jeremy Evans
@ 2011-05-05 19:33 ` Eric Wong
0 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2011-05-05 19:33 UTC (permalink / raw)
To: kgio
Jeremy Evans <code@jeremyevans.net> wrote:
> > I'm not sure why OpenBSD differs from POSIX here:
> > http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
> >
> > Even though PF_UNSPEC == AF_UNSPEC in most systems, I'd rather go with
> > the following patch and single out OpenBSD (and maybe other *BSDs) since
> > "AF_" (address family) makes more sense than "PF_" (protocol family):
>
> It looks like the AF_UNSPEC -> PF_UNSPEC is not necessary, they must be
> defined to the same thing. Why the OpenBSD man page recommends
> PF_UNSPEC, I'm not sure. It looks like the memset was the necessary
> fix.
OK, thanks!
--
Eric Wong
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Fixes for OpenBSD
2011-05-05 18:18 Fixes for OpenBSD Jeremy Evans
2011-05-05 18:45 ` Eric Wong
@ 2011-05-05 19:35 ` Eric Wong
1 sibling, 0 replies; 5+ messages in thread
From: Eric Wong @ 2011-05-05 19:35 UTC (permalink / raw)
To: kgio
Jeremy Evans <code@jeremyevans.net> wrote:
> 1) Failure:
> test_wait_writable_set(TestKgioTcpConnect) [test/test_tcp_connect.rb:69]:
> <"waited"> expected but was
> <nil>.
Ah, some TCP stacks may optimize loopback connections so non-blocking
connect() won't return with EAGAIN (like with Unix sockets). I'll just
disable the test on non-Linux.
> Hope this helps,
Thank you very much for your feedback :)
--
Eric Wong
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-05-05 19:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-05 18:18 Fixes for OpenBSD Jeremy Evans
2011-05-05 18:45 ` Eric Wong
2011-05-05 19:29 ` Jeremy Evans
2011-05-05 19:33 ` Eric Wong
2011-05-05 19:35 ` Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/kgio.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).