[svn] commit: r4056 - /branches/trac448/src/lib/asiolink/tests/asiolink_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 28 20:41:50 UTC 2010
Author: jinmei
Date: Tue Dec 28 20:41:49 2010
New Revision: 4056
Log:
added workaround for Solaris: if SO_RCVTIMEO is rejected due to EOPNOTSUPP switch to "no wait recv()"
Modified:
branches/trac448/src/lib/asiolink/tests/asiolink_unittest.cc
Modified: branches/trac448/src/lib/asiolink/tests/asiolink_unittest.cc
==============================================================================
--- branches/trac448/src/lib/asiolink/tests/asiolink_unittest.cc (original)
+++ branches/trac448/src/lib/asiolink/tests/asiolink_unittest.cc Tue Dec 28 20:41:49 2010
@@ -338,11 +338,21 @@
// In order to prevent the test from hanging in such a worst case
// we add an ad hoc timeout.
const struct timeval timeo = { 10, 0 };
+ int recv_options = 0;
if (setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, &timeo,
sizeof(timeo))) {
- isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
- }
- const int ret = recv(sock_, buffer, size, 0);
+ if (errno == EOPNOTSUPP) {
+ // Workaround for Solaris: it doesn't accept SO_RCVTIMEO
+ // with the error of EOPNOTSUPP. Since this is a workaround
+ // for rare error cases anyway, we simply switch to the
+ // "don't wait" mode. If we still find an error in recv()
+ // can happen often we'll consider a more complete solution.
+ recv_options = MSG_DONTWAIT;
+ } else {
+ isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
+ }
+ }
+ const int ret = recv(sock_, buffer, size, recv_options);
if (ret < 0) {
isc_throw(IOError, "recvfrom failed: " << strerror(errno));
}
@@ -710,13 +720,18 @@
// Read up to 3 packets. Use some ad hoc timeout to prevent an infinite
// block (see also recvUDP()).
const struct timeval timeo = { 10, 0 };
+ int recv_options = 0;
if (setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo))) {
- isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
+ if (errno == EOPNOTSUPP) { // see ASIOLinkTest::recvUDP()
+ recv_options = MSG_DONTWAIT;
+ } else {
+ isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
+ }
}
int num = 0;
do {
char inbuff[512];
- if (recv(sock_, inbuff, sizeof(inbuff), 0) < 0) {
+ if (recv(sock_, inbuff, sizeof(inbuff), recv_options) < 0) {
num = -1;
break;
}
More information about the bind10-changes
mailing list