|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
test-writev: use this to figure out if your writev() does intelligent
|
|
Packit |
90a5c9 |
things on the network. Some writev()s when given multiple buffers
|
|
Packit |
90a5c9 |
will break them up into multiple packets, which is a waste.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Linux prior to 2.0.31 has this problem.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Solaris 2.5, 2.5.1 doesn't appear to, 2.6 hasn't been tested.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
IRIX 5.3 doesn't have this problem.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
To use this you want to snoop the wire with tcpdump, and then run
|
|
Packit |
90a5c9 |
"test-writev a.b.c.d port#" ... against some TCP service on another
|
|
Packit |
90a5c9 |
box. For example you can run it against port 80 on another server.
|
|
Packit |
90a5c9 |
You want to look to see how many data packets are sent, you're hoping
|
|
Packit |
90a5c9 |
only one of size 300 is sent.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <stdio.h>
|
|
Packit |
90a5c9 |
#include <sys/types.h>
|
|
Packit |
90a5c9 |
#include <sys/socket.h>
|
|
Packit |
90a5c9 |
#include <netinet/in.h>
|
|
Packit |
90a5c9 |
#include <stdlib.h>
|
|
Packit |
90a5c9 |
#include <unistd.h>
|
|
Packit |
90a5c9 |
#include <arpa/inet.h>
|
|
Packit |
90a5c9 |
#include <sys/uio.h>
|
|
Packit |
90a5c9 |
#include <errno.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef INADDR_NONE
|
|
Packit |
90a5c9 |
#define INADDR_NONE (-1ul)
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void main( int argc, char **argv )
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct sockaddr_in server_addr;
|
|
Packit |
90a5c9 |
int s;
|
|
Packit |
90a5c9 |
struct iovec vector[3];
|
|
Packit |
90a5c9 |
char buf[100];
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
const int just_say_no = 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if( argc != 3 ) {
|
|
Packit |
90a5c9 |
usage:
|
|
Packit |
90a5c9 |
fprintf( stderr, "usage: test-writev a.b.c.d port#\n" );
|
|
Packit |
90a5c9 |
exit( 1 );
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
server_addr.sin_family = AF_INET;
|
|
Packit |
90a5c9 |
server_addr.sin_addr.s_addr = inet_addr( argv[1] );
|
|
Packit |
90a5c9 |
if( server_addr.sin_addr.s_addr == INADDR_NONE ) {
|
|
Packit |
90a5c9 |
fprintf( stderr, "bogus address\n" );
|
|
Packit |
90a5c9 |
goto usage;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
server_addr.sin_port = htons( atoi( argv[2] ) );
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s = socket( AF_INET, SOCK_STREAM, 0 );
|
|
Packit |
90a5c9 |
if( s < 0 ) {
|
|
Packit |
90a5c9 |
perror("socket");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if( connect( s, (struct sockaddr *)&server_addr, sizeof( server_addr ) )
|
|
Packit |
90a5c9 |
!= 0 ) {
|
|
Packit |
90a5c9 |
perror("connect");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if( setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
|
|
Packit |
90a5c9 |
sizeof(just_say_no)) != 0 ) {
|
|
Packit |
90a5c9 |
perror( "TCP_NODELAY" );
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* now build up a two part writev and write it out */
|
|
Packit |
90a5c9 |
for( i = 0; i < sizeof( buf ); ++i ) {
|
|
Packit |
90a5c9 |
buf[i] = 'x';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
vector[0].iov_base = buf;
|
|
Packit |
90a5c9 |
vector[0].iov_len = sizeof(buf);
|
|
Packit |
90a5c9 |
vector[1].iov_base = buf;
|
|
Packit |
90a5c9 |
vector[1].iov_len = sizeof(buf);
|
|
Packit |
90a5c9 |
vector[2].iov_base = buf;
|
|
Packit |
90a5c9 |
vector[2].iov_len = sizeof(buf);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
i = writev( s, &vector[0], 3 );
|
|
Packit |
90a5c9 |
fprintf( stdout, "i=%d, errno=%d\n", i, errno );
|
|
Packit |
90a5c9 |
exit(0);
|
|
Packit |
90a5c9 |
}
|