2 test-writev: use this to figure out if your writev() does intelligent
3 things on the network. Some writev()s when given multiple buffers
4 will break them up into multiple packets, which is a waste.
6 Linux prior to 2.0.31 has this problem.
8 Solaris 2.5, 2.5.1 doesn't appear to, 2.6 hasn't been tested.
10 IRIX 5.3 doesn't have this problem.
12 To use this you want to snoop the wire with tcpdump, and then run
13 "test-writev a.b.c.d port#" ... against some TCP service on another
14 box. For example you can run it against port 80 on another server.
15 You want to look to see how many data packets are sent, you're hoping
16 only one of size 300 is sent.
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
25 #include <arpa/inet.h>
30 #define INADDR_NONE (-1ul)
33 void main( int argc, char **argv )
35 struct sockaddr_in server_addr;
37 struct iovec vector[3];
40 const int just_say_no = 1;
44 fprintf( stderr, "usage: test-writev a.b.c.d port#\n" );
47 server_addr.sin_family = AF_INET;
48 server_addr.sin_addr.s_addr = inet_addr( argv[1] );
49 if( server_addr.sin_addr.s_addr == INADDR_NONE ) {
50 fprintf( stderr, "bogus address\n" );
53 server_addr.sin_port = htons( atoi( argv[2] ) );
55 s = socket( AF_INET, SOCK_STREAM, 0 );
60 if( connect( s, (struct sockaddr *)&server_addr, sizeof( server_addr ) )
66 if( setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
67 sizeof(just_say_no)) != 0 ) {
68 perror( "TCP_NODELAY" );
71 /* now build up a two part writev and write it out */
72 for( i = 0; i < sizeof( buf ); ++i ) {
75 vector[0].iov_base = buf;
76 vector[0].iov_len = sizeof(buf);
77 vector[1].iov_base = buf;
78 vector[1].iov_len = sizeof(buf);
79 vector[2].iov_base = buf;
80 vector[2].iov_len = sizeof(buf);
82 i = writev( s, &vector[0], 3 );
83 fprintf( stdout, "i=%d, errno=%d\n", i, errno );