diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/gnunet-transport-wlan-receiver.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/gnunet-transport-wlan-receiver.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-receiver.c | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c index 9b31377e7..c6adeec0a 100644 --- a/src/transport/gnunet-transport-wlan-receiver.c +++ b/src/transport/gnunet-transport-wlan-receiver.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2012 GNUnet e.V. | 3 | Copyright (C) 2012 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -28,7 +28,7 @@ | |||
28 | #include "plugin_transport_wlan.h" | 28 | #include "plugin_transport_wlan.h" |
29 | 29 | ||
30 | int | 30 | int |
31 | main (int argc, char *argv[]) | 31 | main(int argc, char *argv[]) |
32 | { | 32 | { |
33 | char msg_buf[65536]; | 33 | char msg_buf[65536]; |
34 | unsigned long long count; | 34 | unsigned long long count; |
@@ -40,75 +40,75 @@ main (int argc, char *argv[]) | |||
40 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ | 40 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ |
41 | 41 | ||
42 | if (2 != argc) | 42 | if (2 != argc) |
43 | { | 43 | { |
44 | fprintf (stderr, | 44 | fprintf(stderr, |
45 | "This program must be started with the interface name as argument.\n"); | 45 | "This program must be started with the interface name as argument.\n"); |
46 | fprintf (stderr, | 46 | fprintf(stderr, |
47 | "Usage: %s interface-name\n" | 47 | "Usage: %s interface-name\n" |
48 | "e.g. %s mon0\n", | 48 | "e.g. %s mon0\n", |
49 | argv[0], | 49 | argv[0], |
50 | argv[0]); | 50 | argv[0]); |
51 | return 1; | 51 | return 1; |
52 | } | 52 | } |
53 | 53 | ||
54 | /* Setup communication pipeline first */ | 54 | /* Setup communication pipeline first */ |
55 | if (pipe (commpipe)) | 55 | if (pipe(commpipe)) |
56 | { | 56 | { |
57 | fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); | 57 | fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); |
58 | exit (1); | 58 | exit(1); |
59 | } | 59 | } |
60 | 60 | ||
61 | /* Attempt to fork and check for errors */ | 61 | /* Attempt to fork and check for errors */ |
62 | if ((pid = fork ()) == -1) | 62 | if ((pid = fork()) == -1) |
63 | { | 63 | { |
64 | fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); | 64 | fprintf(stderr, "Failed to fork: %s\n", strerror(errno)); |
65 | exit (1); | 65 | exit(1); |
66 | } | 66 | } |
67 | 67 | ||
68 | if (pid) | 68 | if (pid) |
69 | { | ||
70 | /* A positive (non-negative) PID indicates the parent process */ | ||
71 | if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ | ||
72 | fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); | ||
73 | start = time (NULL); | ||
74 | count = 0; | ||
75 | while (1) | ||
76 | { | 69 | { |
77 | ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); | 70 | /* A positive (non-negative) PID indicates the parent process */ |
78 | if (0 > ret) | 71 | if (0 != close(commpipe[1])) /* Close unused side of pipe (in side) */ |
79 | { | 72 | fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); |
80 | fprintf (stderr, "read failed: %s\n", strerror (errno)); | 73 | start = time(NULL); |
81 | break; | 74 | count = 0; |
82 | } | 75 | while (1) |
83 | count += ret; | 76 | { |
84 | akt = time (NULL); | 77 | ret = read(commpipe[0], msg_buf, sizeof(msg_buf)); |
85 | if (akt - start > 30) | 78 | if (0 > ret) |
86 | { | 79 | { |
87 | bytes_per_s = count / (akt - start); | 80 | fprintf(stderr, "read failed: %s\n", strerror(errno)); |
88 | bytes_per_s /= 1024; | 81 | break; |
89 | printf ("recv %f kb/s\n", bytes_per_s); | 82 | } |
90 | start = akt; | 83 | count += ret; |
91 | count = 0; | 84 | akt = time(NULL); |
92 | } | 85 | if (akt - start > 30) |
86 | { | ||
87 | bytes_per_s = count / (akt - start); | ||
88 | bytes_per_s /= 1024; | ||
89 | printf("recv %f kb/s\n", bytes_per_s); | ||
90 | start = akt; | ||
91 | count = 0; | ||
92 | } | ||
93 | } | ||
93 | } | 94 | } |
94 | } | ||
95 | else | 95 | else |
96 | { | ||
97 | /* A zero PID indicates that this is the child process */ | ||
98 | (void) close (1); | ||
99 | if (-1 == | ||
100 | dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ | ||
101 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); | ||
102 | (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ | ||
103 | /* Replace the child fork with a new process */ | ||
104 | if (execlp ("gnunet-helper-transport-wlan", | ||
105 | "gnunet-helper-transport-wlan", | ||
106 | argv[1], | ||
107 | NULL) == -1) | ||
108 | { | 96 | { |
109 | fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); | 97 | /* A zero PID indicates that this is the child process */ |
110 | _exit (1); | 98 | (void)close(1); |
99 | if (-1 == | ||
100 | dup2(commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ | ||
101 | fprintf(stderr, "dup2 failed: %s\n", strerror(errno)); | ||
102 | (void)close(commpipe[0]); /* Close unused side of pipe (in side) */ | ||
103 | /* Replace the child fork with a new process */ | ||
104 | if (execlp("gnunet-helper-transport-wlan", | ||
105 | "gnunet-helper-transport-wlan", | ||
106 | argv[1], | ||
107 | NULL) == -1) | ||
108 | { | ||
109 | fprintf(stderr, "Could not start gnunet-helper-transport-wlan!"); | ||
110 | _exit(1); | ||
111 | } | ||
111 | } | 112 | } |
112 | } | ||
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |