Permalink
Browse files

Revert usage of polling loop because it does not work properly and us…

…e a sleep call.
  • Loading branch information...
1 parent 06f36d9 commit 27142df02d35862142985b0b85fbc7c6db5adc86 Caleb James DeLisle committed Dec 10, 2012
View
@@ -68,24 +68,6 @@ static uint8_t sendMessage(struct Message* message, struct Interface* iface)
return 0;
}
-/**
- * When a TUN device first comes up, on some platforms (BSD)
- * using it right away creates a race condition.
- * This busy polls it until it becomes "ready" and then returns.
- */
-static inline void pollTun(Socket sock, struct Log* logger)
-{
- Log_debug(logger, "Waiting for tun device to become ready");
- int i = 0;
- ssize_t length;
- do {
- Assert_always(++i < 100000);
- uint8_t buff[24];
- length = read(sock, buff, 24);
- } while (length > 0 || Errno_get() == Errno_EHOSTDOWN);
- Log_debug(logger, "Polled tun [%d] times", i);
-}
-
struct TUNInterface* TUNInterface_new(void* tunSocket,
struct EventBase* base,
struct Allocator* allocator,
@@ -94,7 +76,6 @@ struct TUNInterface* TUNInterface_new(void* tunSocket,
Socket tunSock = (Socket) ((intptr_t) tunSocket);
Socket_makeNonBlocking(tunSock);
- pollTun(tunSock, logger);
struct TUNInterface_pvt* tun = Allocator_clone(allocator, (&(struct TUNInterface_pvt) {
.pub = {
@@ -102,8 +102,8 @@ static void fail(void* ignored)
int main(int argc, char** argv)
{
- // TODO: fix TUNConfigurator_addIp4Address() for illumos.
- #ifdef Illumos
+ // TODO: fix TUNConfigurator_addIp4Address() for illumos, OSX, BSD.
+ #if defined(Illumos) || defined(OSX) || defined(BSD)
return 0;
#endif
@@ -38,9 +38,8 @@
#include "wire/Ethernet.h"
#include "wire/Headers.h"
-#if defined(BSD) || defined(Illumos)
- #include <sys/socket.h>
-#endif
+#include <unistd.h>
+#include <sys/socket.h>
#include <netinet/in.h>
const uint8_t testAddrA[] = {0xfd,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
@@ -120,6 +119,12 @@ int main(int argc, char** argv)
TUNConfigurator_addIp6Address(assignedInterfaceName, testAddrA, 126, logger, NULL);
struct TUNInterface* tun = TUNInterface_new(tunPtr, base, alloc, logger);
+ #if defined(OSX) || defined(BSD)
+ // Mac OSX and BSD do not set up their TUN devices synchronously.
+ // There should be a proper way to do this but I'm too lazy to look for it atm.
+ usleep(10 * 1000);
+ #endif
+
struct UDPInterface* udp = UDPInterface_new(base, "[fd00::1]", alloc, NULL, logger, &ic);
struct sockaddr_in6 sin = { .sin6_family = AF_INET6 };

0 comments on commit 27142df

Please sign in to comment.