bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / test / test-writev.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18     test-writev: use this to figure out if your writev() does intelligent
19     things on the network.  Some writev()s when given multiple buffers
20     will break them up into multiple packets, which is a waste.
21
22     Linux prior to 2.0.31 has this problem.
23
24     Solaris 2.5, 2.5.1 doesn't appear to, 2.6 hasn't been tested.
25
26     IRIX 5.3 doesn't have this problem.
27
28     To use this you want to snoop the wire with tcpdump, and then run
29     "test-writev a.b.c.d port#" ... against some TCP service on another
30     box.  For example you can run it against port 80 on another server.
31     You want to look to see how many data packets are sent, you're hoping
32     only one of size 300 is sent.
33 */
34
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <arpa/inet.h>
42 #include <sys/uio.h>
43 #include <errno.h>
44
45 #ifndef INADDR_NONE
46 #define INADDR_NONE (-1ul)
47 #endif
48
49 void main( int argc, char **argv )
50 {
51     struct sockaddr_in server_addr;
52     int s;
53     struct iovec vector[3];
54     char buf[100];
55     int i;
56     const int just_say_no = 1;
57
58     if( argc != 3 ) {
59 usage:
60         fprintf( stderr, "usage: test-writev a.b.c.d port#\n" );
61         exit( 1 );
62     }
63     server_addr.sin_family = AF_INET;
64     server_addr.sin_addr.s_addr = inet_addr( argv[1] );
65     if( server_addr.sin_addr.s_addr == INADDR_NONE ) {
66         fprintf( stderr, "bogus address\n" );
67         goto usage;
68     }
69     server_addr.sin_port = htons( atoi( argv[2] ) );
70
71     s = socket( AF_INET, SOCK_STREAM, 0 );
72     if( s < 0 ) {
73         perror("socket");
74         exit(1);
75     }
76     if( connect( s, (struct sockaddr *)&server_addr, sizeof( server_addr ) )
77         != 0 ) {
78         perror("connect");
79         exit(1);
80     }
81
82     if( setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
83         sizeof(just_say_no)) != 0 ) {
84         perror( "TCP_NODELAY" );
85         exit(1);
86     }
87     /* now build up a two part writev and write it out */
88     for( i = 0; i < sizeof( buf ); ++i ) {
89         buf[i] = 'x';
90     }
91     vector[0].iov_base = buf;
92     vector[0].iov_len = sizeof(buf);
93     vector[1].iov_base = buf;
94     vector[1].iov_len = sizeof(buf);
95     vector[2].iov_base = buf;
96     vector[2].iov_len = sizeof(buf);
97
98     i = writev( s, &vector[0], 3 );
99     fprintf( stdout, "i=%d, errno=%d\n", i, errno );
100     exit(0);
101 }