summaryrefslogtreecommitdiffstats
path: root/tun.c
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-12-08 10:51:32 +0900
committerLorenzo Colitti <lorenzo@google.com>2014-12-08 16:59:25 +0900
commitb20719ebf403b16d36a231aeef96607f8c7aa252 (patch)
treed36b835d6b213291b7230099fdb9fb7a8199b693 /tun.c
parent6b2007aacd13344c9bc73d5d858bd903b432c228 (diff)
downloadandroid_external_android-clat-b20719ebf403b16d36a231aeef96607f8c7aa252.tar.gz
android_external_android-clat-b20719ebf403b16d36a231aeef96607f8c7aa252.tar.bz2
android_external_android-clat-b20719ebf403b16d36a231aeef96607f8c7aa252.zip
Add a microbenchmark for tun write performance.
Change-Id: Id73888d25afd9253634356436c57afec630a0846
Diffstat (limited to 'tun.c')
-rw-r--r--tun.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/tun.c b/tun.c
index a1b7254..49f0ea7 100644
--- a/tun.c
+++ b/tun.c
@@ -64,6 +64,26 @@ int tun_alloc(char *dev, int fd) {
return 0;
}
-void send_tun(int fd, clat_packet out, int iov_len) {
- writev(fd, out, iov_len);
+/* function: set_nonblocking
+ * sets a filedescriptor to non-blocking mode
+ * fd - the filedescriptor
+ * returns: 0 on success, -1 on failure
+ */
+int set_nonblocking(int fd) {
+ int flags = fcntl(fd, F_GETFL);
+ if (flags == -1) {
+ return flags;
+ }
+ return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+/* function: send_tun
+ * sends a clat_packet to a tun interface
+ * fd - the tun filedescriptor
+ * out - the packet to send
+ * iov_len - the number of entries in the clat_packet
+ * returns: number of bytes read on success, -1 on failure
+ */
+int send_tun(int fd, clat_packet out, int iov_len) {
+ return writev(fd, out, iov_len);
}