diff options
Diffstat (limited to 'src/transport/test_transport_api_limited_sockets.c')
-rw-r--r-- | src/transport/test_transport_api_limited_sockets.c | 96 |
1 files changed, 17 insertions, 79 deletions
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index 25e8550c0..1b82ade70 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c | |||
@@ -35,20 +35,11 @@ | |||
35 | */ | 35 | */ |
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
37 | 37 | ||
38 | /** | ||
39 | * How long until we give up on transmitting the message? | ||
40 | */ | ||
41 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
42 | |||
43 | #define MTYPE 12345 | ||
44 | |||
45 | #define MAX_FILES 50 | 38 | #define MAX_FILES 50 |
46 | 39 | ||
47 | 40 | ||
48 | #if HAVE_SETRLIMIT | 41 | #if HAVE_SETRLIMIT |
49 | 42 | ||
50 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
51 | |||
52 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 43 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
53 | 44 | ||
54 | 45 | ||
@@ -62,8 +53,10 @@ notify_receive (void *cls, | |||
62 | "Received message of type %d from peer %s!\n", | 53 | "Received message of type %d from peer %s!\n", |
63 | ntohs (message->type), | 54 | ntohs (message->type), |
64 | GNUNET_i2s (sender)); | 55 | GNUNET_i2s (sender)); |
65 | if ((MTYPE == ntohs (message->type)) && | 56 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == |
66 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 57 | ntohs (message->type)) && |
58 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == | ||
59 | ntohs (message->size)) ) | ||
67 | { | 60 | { |
68 | ccc->global_ret = GNUNET_OK; | 61 | ccc->global_ret = GNUNET_OK; |
69 | } | 62 | } |
@@ -75,83 +68,27 @@ notify_receive (void *cls, | |||
75 | } | 68 | } |
76 | 69 | ||
77 | 70 | ||
78 | static size_t | ||
79 | notify_ready (void *cls, size_t size, void *buf) | ||
80 | { | ||
81 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
82 | struct GNUNET_MessageHeader *hdr; | ||
83 | |||
84 | th = NULL; | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
86 | "Transmitting message with %u bytes to peer %s\n", | ||
87 | (unsigned int) sizeof (struct GNUNET_MessageHeader), | ||
88 | GNUNET_i2s (&p->id)); | ||
89 | GNUNET_assert (size >= 256); | ||
90 | if (buf != NULL) | ||
91 | { | ||
92 | hdr = buf; | ||
93 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
94 | hdr->type = htons (MTYPE); | ||
95 | } | ||
96 | return sizeof (struct GNUNET_MessageHeader); | ||
97 | } | ||
98 | |||
99 | |||
100 | static void | ||
101 | notify_disconnect (void *cls, | ||
102 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
103 | const struct GNUNET_PeerIdentity *other) | ||
104 | { | ||
105 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
106 | me, | ||
107 | other); | ||
108 | if (NULL != th) | ||
109 | { | ||
110 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
111 | th = NULL; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | |||
116 | static void | ||
117 | custom_shutdown (void *cls) | ||
118 | { | ||
119 | if (NULL != th) | ||
120 | { | ||
121 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
122 | th = NULL; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | |||
127 | static void | ||
128 | sendtask (void *cls) | ||
129 | { | ||
130 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[0]->th, | ||
131 | &ccc->p[1]->id, | ||
132 | 256, | ||
133 | TIMEOUT, | ||
134 | ¬ify_ready, | ||
135 | ccc->p[0]); | ||
136 | } | ||
137 | |||
138 | |||
139 | int | 71 | int |
140 | main (int argc, char *argv[]) | 72 | main (int argc, char *argv[]) |
141 | { | 73 | { |
74 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
75 | .num_messages = 1 | ||
76 | }; | ||
142 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 77 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
143 | .connect_continuation = &sendtask, | 78 | .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send, |
79 | .connect_continuation_cls = &sc, | ||
144 | .config_file = "test_transport_api_data.conf", | 80 | .config_file = "test_transport_api_data.conf", |
145 | .rec = ¬ify_receive, | 81 | .rec = ¬ify_receive, |
146 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 82 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
147 | .nd = ¬ify_disconnect, | 83 | .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect, |
148 | .shutdown_task = &custom_shutdown, | 84 | .timeout = TIMEOUT, |
149 | .timeout = TIMEOUT | 85 | .global_ret = GNUNET_SYSERR |
150 | }; | 86 | }; |
151 | struct rlimit r_file_old; | 87 | struct rlimit r_file_old; |
152 | struct rlimit r_file_new; | 88 | struct rlimit r_file_new; |
153 | int res; | 89 | int res; |
154 | 90 | ||
91 | sc.ccc = &my_ccc; | ||
155 | res = getrlimit (RLIMIT_NOFILE, | 92 | res = getrlimit (RLIMIT_NOFILE, |
156 | &r_file_old); | 93 | &r_file_old); |
157 | r_file_new.rlim_cur = MAX_FILES; | 94 | r_file_new.rlim_cur = MAX_FILES; |
@@ -183,8 +120,9 @@ main (int argc, char *argv[]) | |||
183 | int | 120 | int |
184 | main (int argc, char *argv[]) | 121 | main (int argc, char *argv[]) |
185 | { | 122 | { |
186 | fprintf (stderr, "Cannot run test on this system\n"); | 123 | fprintf (stderr, |
187 | return 0; | 124 | "Cannot run test on this system\n"); |
125 | return 77; | ||
188 | } | 126 | } |
189 | 127 | ||
190 | #endif | 128 | #endif |