diff options
author | Chia-chi Yeh <chiachi@android.com> | 2011-06-16 19:03:57 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-16 19:03:57 -0700 |
commit | 4d4faf9e9119c186d96e0918fc9d6395188abd31 (patch) | |
tree | b0695ce0f62cb5a45dc899ad46593476d88d3089 | |
parent | 452eec33d667f9e705b57e60948b070536fbc1b4 (diff) | |
parent | 84bf7390ea6b9a82bbd036b64c41d7c120b7f159 (diff) | |
download | frameworks_base-4d4faf9e9119c186d96e0918fc9d6395188abd31.zip frameworks_base-4d4faf9e9119c186d96e0918fc9d6395188abd31.tar.gz frameworks_base-4d4faf9e9119c186d96e0918fc9d6395188abd31.tar.bz2 |
Merge "VPN: make the file descriptor non-blocking by default."
-rw-r--r-- | services/jni/com_android_server_connectivity_Vpn.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/services/jni/com_android_server_connectivity_Vpn.cpp b/services/jni/com_android_server_connectivity_Vpn.cpp index 206df25..ae7fbfe 100644 --- a/services/jni/com_android_server_connectivity_Vpn.cpp +++ b/services/jni/com_android_server_connectivity_Vpn.cpp @@ -55,6 +55,7 @@ static int create_interface(int mtu, char *name, int *index) { int tun = open("/dev/tun", O_RDWR); int inet4 = socket(AF_INET, SOCK_DGRAM, 0); + int flags; ifreq ifr4; memset(&ifr4, 0, sizeof(ifr4)); @@ -86,6 +87,13 @@ static int create_interface(int mtu, char *name, int *index) goto error; } + // Make it non-blocking. + flags = fcntl(tun, F_GETFL, 0); + if (flags == -1 || fcntl(tun, F_SETFL, flags | O_NONBLOCK)) { + LOGE("Cannot set non-blocking on %s: %s", ifr4.ifr_name, strerror(errno)); + goto error; + } + strcpy(name, ifr4.ifr_name); *index = ifr4.ifr_ifindex; close(inet4); |