@@ -47,8 +47,8 @@ typedef struct {
4747 WOLFSSL_CTX * ctx ;
4848} thread_args_t ;
4949
50- static void safer_shutdown (thread_args_t * args );
51- static void * client_work (void * arg );
50+ static void safer_shutdown (thread_args_t * args );
51+ static void * client_work (void * arg );
5252
5353int
5454main (int argc ,
@@ -65,13 +65,20 @@ main(int argc,
6565 memset (threads , 0 , sizeof (threads ));
6666 memset (args , 0 , sizeof (args ));
6767
68- while ((opt = getopt (argc , argv , "vt:n: :?" )) != -1 ) {
68+ while ((opt = getopt (argc , argv , "t :?" )) != -1 ) {
6969 switch (opt ) {
7070 case 't' :
7171 n_threads = atoi (optarg );
7272 break ;
7373
7474 case '?' :
75+ printf ("usage:\n" );
76+ printf (" ./client-dtls-threaded [-t n]\n" );
77+ printf ("\n" );
78+ printf ("description:\n" );
79+ printf (" A simple dtls client with configurable threadpool.\n" );
80+ printf (" Num allowed threads is: 1 <= n <= %d\n" ,
81+ DTLS_NUMTHREADS );
7582 default :
7683 return EXIT_FAILURE ;
7784 }
@@ -103,7 +110,7 @@ main(int argc,
103110 ret = pthread_create (& threads [i ], NULL , client_work , & args [i ]);
104111
105112 if (ret == 0 ) {
106- printf ("info: spawned thread: %ld\n" , threads [i ]);
113+ printf ("info: spawned thread: %ld\n" , ( long ) threads [i ]);
107114 }
108115 else {
109116 printf ("error: pthread_create returned %d\n" , ret );
@@ -115,7 +122,7 @@ main(int argc,
115122 for (size_t i = 0 ; i < n_threads ; ++ i ) {
116123 if (threads [i ]) {
117124 pthread_join (threads [i ], NULL );
118- printf ("info: joined thread: %ld\n" , threads [i ]);
125+ printf ("info: joined thread: %ld\n" , ( long ) threads [i ]);
119126 threads [i ] = 0 ;
120127 }
121128 }
@@ -168,12 +175,14 @@ client_work(void * args)
168175 return NULL ;
169176 }
170177
178+ printf ("info: opened socket: %d\n" , thread_args -> activefd );
179+
171180 /* Set the file descriptor for ssl and connect with ssl variable */
172181 wolfSSL_set_fd (thread_args -> ssl , thread_args -> activefd );
173182 if (wolfSSL_connect (thread_args -> ssl ) != SSL_SUCCESS ) {
174183 err1 = wolfSSL_get_error (thread_args -> ssl , 0 );
175184 printf ("error: thread %ld: wolfSSL_connect returned = %d, %s\n" ,
176- pthread_self (), err1 ,
185+ ( long ) pthread_self (), err1 ,
177186 wolfSSL_ERR_reason_error_string (err1 ));
178187 return NULL ;
179188 }
@@ -185,9 +194,12 @@ client_work(void * args)
185194 const char * tid_str = NULL ; /* Str to thread id in response. */
186195
187196 for (size_t i = 0 ; i < 4 ; ++ i ) {
197+ memset (send_msg , '\0' , sizeof (send_msg ));
198+ memset (recv_msg , '\0' , sizeof (recv_msg ));
199+
188200 char seq = '0' + (int ) i ;
189201 sprintf (send_msg , "msg %zu from client thread %ld\n" , i ,
190- pthread_self ());
202+ ( long ) pthread_self ());
191203
192204 n_bytes = wolfSSL_write (thread_args -> ssl , send_msg , strlen (send_msg ));
193205
@@ -210,7 +222,7 @@ client_work(void * args)
210222 /* Check the server replied with the correct sequence record, e.g.:
211223 * "msg 2 from server thread 140146322425536" */
212224 if (recv_msg [4 ] != seq ) {
213- printf ("error: got msg %c, expected %c\n" , recv_msg [5 ], seq );
225+ printf ("error: got msg %c, expected %c\n" , recv_msg [4 ], seq );
214226 break ;
215227 }
216228
@@ -223,12 +235,12 @@ client_work(void * args)
223235 /* Compare saved thread id. */
224236 if (server_tid != atol (tid_str )) {
225237 printf ("error: got rsp from server thread %ld, expected %ld\n" ,
226- server_tid , atol (tid_str ));
238+ server_tid , atol (tid_str ));
227239 break ;
228240 }
229241 else {
230- printf ("info: got response from server thread %ld\n" ,
231- server_tid );
242+ printf ("info: got response from server thread %ld\n" ,
243+ server_tid );
232244 }
233245 }
234246
@@ -265,5 +277,3 @@ safer_shutdown(thread_args_t * args)
265277
266278 return ;
267279}
268-
269-
0 commit comments