@@ -44,7 +44,8 @@ static const char *__doc__=
4444#define RUN_RECVMMSG 0x2
4545#define RUN_RECVFROM 0x4
4646#define RUN_READ 0x8
47- #define RUN_ALL (RUN_RECVMSG | RUN_RECVMMSG | RUN_RECVFROM | RUN_READ)
47+ #define RUN_RECV 0x10
48+ #define RUN_ALL (RUN_RECVMSG | RUN_RECVMMSG | RUN_RECVFROM | RUN_READ |RUN_RECV)
4849
4950struct sink_params {
5051 struct params_common c ;
@@ -79,6 +80,7 @@ static const struct option long_options[] = {
7980 {"recvfrom" , no_argument , NULL , 't' },
8081 {"recvmsg" , no_argument , NULL , 'u' },
8182 {"recvmmsg" , no_argument , NULL , 'U' },
83+ {"recv" , no_argument , NULL , 176 },
8284 /* Other options */
8385 {"help" , no_argument , NULL , 'h' },
8486 {"ipv4" , no_argument , NULL , '4' },
@@ -321,6 +323,41 @@ static int sink_with_recvfrom(int sockfd, struct sink_params *p,
321323 exit (EXIT_FAIL_SOCK );
322324}
323325
326+ static int sink_with_recv (int sockfd , struct sink_params * p ,
327+ struct time_bench_record * r ) {
328+ int i , res ;
329+ uint64_t total = 0 ;
330+ char * buffer = malloc_payload_buffer (p -> buf_sz );
331+ int flags = p -> dontwait ? MSG_DONTWAIT : 0 ;
332+
333+ for (i = 0 ; i < p -> count ; i ++ ) {
334+ res = recv (sockfd , buffer , p -> buf_sz , flags );
335+ if (res < 0 ) {
336+ if (errno == EAGAIN ) {
337+ r -> try_again ++ ;
338+ continue ;
339+ }
340+ goto error ;
341+ }
342+ total += res ;
343+ }
344+ r -> bytes = total ;
345+ if (verbose > 0 )
346+ printf (" - read %lu bytes in %d packets = %lu bytes payload\n" ,
347+ total , i , total / i );
348+
349+ free (buffer );
350+ return (i - r -> try_again );
351+
352+ error : /* ugly construct to make sure the loop is small */
353+ fprintf (stderr , "ERROR: %s() failed (%d) errno(%d) " ,
354+ __func__ , res , errno );
355+ perror ("- recv" );
356+ free (buffer );
357+ close (sockfd );
358+ exit (EXIT_FAIL_SOCK );
359+ }
360+
324361static void setup_msg_name (struct msghdr * msg_hdr ,
325362 struct sockaddr_storage * addr , int family )
326363{
@@ -839,6 +876,7 @@ int main(int argc, char *argv[])
839876 if (c == 'U' ) p .run_flag |= RUN_RECVMMSG ;
840877 if (c == 't' ) p .run_flag |= RUN_RECVFROM ;
841878 if (c == 'T' ) p .run_flag |= RUN_READ ;
879+ if (c == 176 ) p .run_flag |= RUN_RECV ;
842880 if (c == 'h' || c == '?' ) return usage (argv );
843881 }
844882
@@ -937,6 +975,11 @@ int main(int argc, char *argv[])
937975 time_function (sockfd , & p , "recvfrom" , sink_with_recvfrom );
938976 }
939977
978+ if (p .run_flag & RUN_RECV ) {
979+ init_stats (& p , RUN_RECV );
980+ time_function (sockfd , & p , "recv" , sink_with_recv );
981+ }
982+
940983 close (sockfd );
941984 return 0 ;
942985}
0 commit comments