diff options
author | Chia-chi Yeh <chiachi@android.com> | 2011-06-16 19:01:28 -0700 |
---|---|---|
committer | Chia-chi Yeh <chiachi@android.com> | 2011-06-16 19:01:28 -0700 |
commit | 84bf7390ea6b9a82bbd036b64c41d7c120b7f159 (patch) | |
tree | 7bc7c348ad0d4ab48f88bb0a695ba5fe97e5af2b /services | |
parent | 04ba25c418bc4538e9dc0f047cfb9608d358f679 (diff) | |
download | frameworks_base-84bf7390ea6b9a82bbd036b64c41d7c120b7f159.zip frameworks_base-84bf7390ea6b9a82bbd036b64c41d7c120b7f159.tar.gz frameworks_base-84bf7390ea6b9a82bbd036b64c41d7c120b7f159.tar.bz2 |
VPN: make the file descriptor non-blocking by default.
Change-Id: I89899b2b6a8ac64a4a052ffd501cc0221fab3ffe
Diffstat (limited to 'services')
-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); |