diff options
Diffstat (limited to 'src/transport/gnunet-transport-wlan-receiver.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-receiver.c | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c index c6adeec0a..7f34a957f 100644 --- a/src/transport/gnunet-transport-wlan-receiver.c +++ b/src/transport/gnunet-transport-wlan-receiver.c | |||
@@ -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) | ||
69 | { | 76 | { |
70 | /* A positive (non-negative) PID indicates the parent process */ | 77 | ret = read (commpipe[0], msg_buf, sizeof(msg_buf)); |
71 | if (0 != close(commpipe[1])) /* Close unused side of pipe (in side) */ | 78 | if (0 > ret) |
72 | fprintf(stderr, "Failed to close fd: %s\n", strerror(errno)); | 79 | { |
73 | start = time(NULL); | 80 | fprintf (stderr, "read failed: %s\n", strerror (errno)); |
74 | count = 0; | 81 | break; |
75 | while (1) | 82 | } |
76 | { | 83 | count += ret; |
77 | ret = read(commpipe[0], msg_buf, sizeof(msg_buf)); | 84 | akt = time (NULL); |
78 | if (0 > ret) | 85 | if (akt - start > 30) |
79 | { | 86 | { |
80 | fprintf(stderr, "read failed: %s\n", strerror(errno)); | 87 | bytes_per_s = count / (akt - start); |
81 | break; | 88 | bytes_per_s /= 1024; |
82 | } | 89 | printf ("recv %f kb/s\n", bytes_per_s); |
83 | count += ret; | 90 | start = akt; |
84 | akt = time(NULL); | 91 | count = 0; |
85 | if (akt - start > 30) | 92 | } |
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 | } | ||
94 | } | 93 | } |
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) | ||
96 | { | 108 | { |
97 | /* A zero PID indicates that this is the child process */ | 109 | fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); |
98 | (void)close(1); | 110 | _exit (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 | } | ||
112 | } | 111 | } |
112 | } | ||
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |