82
82
#define MSG_SOCK_DEVMEM 0x2000000
83
83
#endif
84
84
85
+ #define MAX_IOV 1024
86
+
87
+ static size_t max_chunk ;
85
88
static char * server_ip ;
86
89
static char * client_ip ;
87
90
static char * port ;
@@ -834,10 +837,10 @@ static int do_client(struct memory_buffer *mem)
834
837
struct sockaddr_in6 server_sin ;
835
838
struct sockaddr_in6 client_sin ;
836
839
struct ynl_sock * ys = NULL ;
840
+ struct iovec iov [MAX_IOV ];
837
841
struct msghdr msg = {};
838
842
ssize_t line_size = 0 ;
839
843
struct cmsghdr * cmsg ;
840
- struct iovec iov [2 ];
841
844
char * line = NULL ;
842
845
unsigned long mid ;
843
846
size_t len = 0 ;
@@ -893,27 +896,29 @@ static int do_client(struct memory_buffer *mem)
893
896
if (line_size < 0 )
894
897
break ;
895
898
896
- mid = (line_size / 2 ) + 1 ;
897
-
898
- iov [0 ].iov_base = (void * )1 ;
899
- iov [0 ].iov_len = mid ;
900
- iov [1 ].iov_base = (void * )(mid + 2 );
901
- iov [1 ].iov_len = line_size - mid ;
899
+ if (max_chunk ) {
900
+ msg .msg_iovlen =
901
+ (line_size + max_chunk - 1 ) / max_chunk ;
902
+ if (msg .msg_iovlen > MAX_IOV )
903
+ error (1 , 0 ,
904
+ "can't partition %zd bytes into maximum of %d chunks" ,
905
+ line_size , MAX_IOV );
902
906
903
- provider -> memcpy_to_device (mem , (size_t )iov [0 ].iov_base , line ,
904
- iov [0 ].iov_len );
905
- provider -> memcpy_to_device (mem , (size_t )iov [1 ].iov_base ,
906
- line + iov [0 ].iov_len ,
907
- iov [1 ].iov_len );
907
+ for (int i = 0 ; i < msg .msg_iovlen ; i ++ ) {
908
+ iov [i ].iov_base = (void * )(i * max_chunk );
909
+ iov [i ].iov_len = max_chunk ;
910
+ }
908
911
909
- fprintf (stderr ,
910
- "read line_size=%ld iov[0].iov_base=%lu, iov[0].iov_len=%lu, iov[1].iov_base=%lu, iov[1].iov_len=%lu\n" ,
911
- line_size , (unsigned long )iov [0 ].iov_base ,
912
- iov [0 ].iov_len , (unsigned long )iov [1 ].iov_base ,
913
- iov [1 ].iov_len );
912
+ iov [msg .msg_iovlen - 1 ].iov_len =
913
+ line_size - (msg .msg_iovlen - 1 ) * max_chunk ;
914
+ } else {
915
+ iov [0 ].iov_base = 0 ;
916
+ iov [0 ].iov_len = line_size ;
917
+ msg .msg_iovlen = 1 ;
918
+ }
914
919
915
920
msg .msg_iov = iov ;
916
- msg . msg_iovlen = 2 ;
921
+ provider -> memcpy_to_device ( mem , 0 , line , line_size ) ;
917
922
918
923
msg .msg_control = ctrl_data ;
919
924
msg .msg_controllen = sizeof (ctrl_data );
@@ -934,7 +939,8 @@ static int do_client(struct memory_buffer *mem)
934
939
fprintf (stderr , "sendmsg_ret=%d\n" , ret );
935
940
936
941
if (ret != line_size )
937
- error (1 , errno , "Did not send all bytes" );
942
+ error (1 , errno , "Did not send all bytes %d vs %zd" , ret ,
943
+ line_size );
938
944
939
945
wait_compl (socket_fd );
940
946
}
@@ -956,7 +962,7 @@ int main(int argc, char *argv[])
956
962
int is_server = 0 , opt ;
957
963
int ret ;
958
964
959
- while ((opt = getopt (argc , argv , "ls:c:p:v:q:t:f:" )) != -1 ) {
965
+ while ((opt = getopt (argc , argv , "ls:c:p:v:q:t:f:z: " )) != -1 ) {
960
966
switch (opt ) {
961
967
case 'l' :
962
968
is_server = 1 ;
@@ -982,6 +988,9 @@ int main(int argc, char *argv[])
982
988
case 'f' :
983
989
ifname = optarg ;
984
990
break ;
991
+ case 'z' :
992
+ max_chunk = atoi (optarg );
993
+ break ;
985
994
case '?' :
986
995
fprintf (stderr , "unknown option: %c\n" , optopt );
987
996
break ;
0 commit comments