Make the raw socket and the tun fd nonblocking.

Change-Id: I29a3d510ba0b766488bbd66d57829d9aaf70d21d
diff --git a/clatd.c b/clatd.c
index 5cbcc1e..68d250e 100644
--- a/clatd.c
+++ b/clatd.c
@@ -214,7 +214,7 @@
  * mark - the socket mark to use for the sending raw socket
  */
 void open_sockets(struct tun_data *tunnel, uint32_t mark) {
-  int rawsock = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
+  int rawsock = socket(AF_INET6, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_RAW);
   if (rawsock < 0) {
     logmsg(ANDROID_LOG_FATAL, "raw socket failed: %s", strerror(errno));
     exit(1);
@@ -276,6 +276,12 @@
     exit(1);
   }
 
+  error = set_nonblocking(tunnel->fd4);
+  if (error < 0) {
+    logmsg(ANDROID_LOG_FATAL, "set_nonblocking failed: %s", strerror(errno));
+    exit(1);
+  }
+
   configure_tun_ip(tunnel);
 }
 
@@ -292,7 +298,9 @@
   readlen = read(read_fd, buf, PACKETLEN);
 
   if(readlen < 0) {
-    logmsg(ANDROID_LOG_WARN,"read_packet/read error: %s", strerror(errno));
+    if (errno != EAGAIN) {
+      logmsg(ANDROID_LOG_WARN,"read_packet/read error: %s", strerror(errno));
+    }
     return;
   } else if(readlen == 0) {
     logmsg(ANDROID_LOG_WARN,"read_packet/tun interface removed");