appium-ios-tuntap 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.2.4](https://github.com/appium/appium-ios-tuntap/compare/v0.2.3...v0.2.4) (2026-05-13)
2
+
3
+ ### Code Refactoring
4
+
5
+ * eliminate tun_backend_common.cc indirection ([#41](https://github.com/appium/appium-ios-tuntap/issues/41)) ([5fd387e](https://github.com/appium/appium-ios-tuntap/commit/5fd387e230fb772dbf280472dbadb43d131a4a2e))
6
+
1
7
  ## [0.2.3](https://github.com/appium/appium-ios-tuntap/compare/v0.2.2...v0.2.3) (2026-05-13)
2
8
 
3
9
  ## [0.2.2](https://github.com/appium/appium-ios-tuntap/compare/v0.2.1...v0.2.2) (2026-04-30)
package/binding.gyp CHANGED
@@ -4,8 +4,7 @@
4
4
  "target_name": "tuntap",
5
5
  "sources": [
6
6
  "src/tuntap.cc",
7
- "src/native/file_descriptor.cc",
8
- "src/native/tun_backend_common.cc"
7
+ "src/native/file_descriptor.cc"
9
8
  ],
10
9
  "include_dirs": [
11
10
  "<!@(node -p \"require('node-addon-api').include\")"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-ios-tuntap",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Native TUN/TAP interface module for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -33,6 +33,5 @@ public:
33
33
  virtual ssize_t WritePacket(int fd, const uint8_t* data, size_t length, std::string& error) = 0;
34
34
  };
35
35
 
36
- bool SetNonBlocking(int fd, std::string& error);
37
36
  std::unique_ptr<TunPlatformBackend> CreatePlatformBackend();
38
37
 
@@ -14,10 +14,25 @@
14
14
  #include <netinet/in.h>
15
15
  #include <netinet6/in6_var.h>
16
16
 
17
+ #include <fcntl.h>
18
+
17
19
  #define UTUN_CONTROL_NAME "com.apple.net.utun_control"
18
20
 
19
21
  namespace {
20
22
 
23
+ bool SetNonBlocking(int fd, std::string& error) {
24
+ int flags = fcntl(fd, F_GETFL, 0);
25
+ if (flags < 0) {
26
+ error = std::string("Failed to get file descriptor flags: ") + strerror(errno);
27
+ return false;
28
+ }
29
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
30
+ error = std::string("Failed to set non-blocking mode: ") + strerror(errno);
31
+ return false;
32
+ }
33
+ return true;
34
+ }
35
+
21
36
  class DarwinTunBackend : public TunPlatformBackend {
22
37
  public:
23
38
  static constexpr size_t kUtunHeaderSize = 4;
@@ -65,6 +80,10 @@ public:
65
80
  return false;
66
81
  }
67
82
 
83
+ if (!SetNonBlocking(temp_fd.get(), error)) {
84
+ return false;
85
+ }
86
+
68
87
  out.fd = std::move(temp_fd);
69
88
  out.interface_name = std::string(interface_name);
70
89
  return true;
@@ -144,7 +163,7 @@ private:
144
163
 
145
164
  } // namespace
146
165
 
147
- std::unique_ptr<TunPlatformBackend> CreatePlatformTunBackend() {
166
+ std::unique_ptr<TunPlatformBackend> CreatePlatformBackend() {
148
167
  return std::make_unique<DarwinTunBackend>();
149
168
  }
150
169
 
@@ -13,6 +13,20 @@
13
13
  #include <linux/if_tun.h>
14
14
 
15
15
  namespace {
16
+
17
+ bool SetNonBlocking(int fd, std::string& error) {
18
+ int flags = fcntl(fd, F_GETFL, 0);
19
+ if (flags < 0) {
20
+ error = std::string("Failed to get file descriptor flags: ") + strerror(errno);
21
+ return false;
22
+ }
23
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
24
+ error = std::string("Failed to set non-blocking mode: ") + strerror(errno);
25
+ return false;
26
+ }
27
+ return true;
28
+ }
29
+
16
30
  constexpr const char* kTunDevicePath = "/dev/net/tun";
17
31
 
18
32
  class LinuxTunBackend : public TunPlatformBackend {
@@ -49,6 +63,10 @@ public:
49
63
  return false;
50
64
  }
51
65
 
66
+ if (!SetNonBlocking(temp_fd.get(), error)) {
67
+ return false;
68
+ }
69
+
52
70
  out.fd = std::move(temp_fd);
53
71
  out.interface_name = std::string(ifr.ifr_name);
54
72
  return true;
@@ -86,7 +104,7 @@ public:
86
104
 
87
105
  } // namespace
88
106
 
89
- std::unique_ptr<TunPlatformBackend> CreatePlatformTunBackend() {
107
+ std::unique_ptr<TunPlatformBackend> CreatePlatformBackend() {
90
108
  return std::make_unique<LinuxTunBackend>();
91
109
  }
92
110
 
package/src/tuntap.cc CHANGED
@@ -107,11 +107,6 @@ Napi::Value TunDevice::Open(const Napi::CallbackInfo& info) {
107
107
  return Napi::Boolean::New(env, false);
108
108
  }
109
109
 
110
- if (!SetNonBlocking(result.fd.get(), error)) {
111
- Napi::Error::New(env, error).ThrowAsJavaScriptException();
112
- return Napi::Boolean::New(env, false);
113
- }
114
-
115
110
  fd_ = std::move(result.fd);
116
111
  name_ = result.interface_name;
117
112
  is_open_ = true;
@@ -1,27 +0,0 @@
1
- #include "tun_backend.h"
2
-
3
- #include <errno.h>
4
- #include <fcntl.h>
5
- #include <string.h>
6
-
7
- std::unique_ptr<TunPlatformBackend> CreatePlatformTunBackend();
8
-
9
- bool SetNonBlocking(int fd, std::string& error) {
10
- int flags = fcntl(fd, F_GETFL, 0);
11
- if (flags < 0) {
12
- error = std::string("Failed to get file descriptor flags: ") + strerror(errno);
13
- return false;
14
- }
15
-
16
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
17
- error = std::string("Failed to set non-blocking mode: ") + strerror(errno);
18
- return false;
19
- }
20
-
21
- return true;
22
- }
23
-
24
- std::unique_ptr<TunPlatformBackend> CreatePlatformBackend() {
25
- return CreatePlatformTunBackend();
26
- }
27
-