1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms
5 * of the Common Development and Distribution License
6 * (the "License").  You may not use this file except
7 * in compliance with the License.
8 *
9 * You can obtain a copy of the license at
10 * src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing
13 * permissions and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL
16 * HEADER in each file and include the License file at
17 * usr/src/OPENSOLARIS.LICENSE.  If applicable,
18 * add the following below this CDDL HEADER, with the
19 * fields enclosed by brackets "[]" replaced with your
20 * own identifying information: Portions Copyright [yyyy]
21 * [name of copyright owner]
22 *
23 * CDDL HEADER END
24 */
25
26/*
27 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <netinet/in.h>
35#include <netinet/tcp.h>
36#include <arpa/inet.h>
37#include <netdb.h>
38#include <string.h>
39#include <unistd.h>
40#include <stdlib.h>
41#include <stdio.h>
42#include <errno.h>
43
44#include "libmicro.h"
45
46typedef struct {
47	int	ts_fd;
48} tsd_t;
49
50int
51benchmark_init()
52{
53	lm_tsdsize = sizeof (tsd_t);
54
55	(void) sprintf(lm_usage, "setsockopt(TCP_NODELAY)\n");
56
57	return (0);
58}
59
60int
61benchmark_initbatch(void *tsd)
62{
63
64	tsd_t			*ts = (tsd_t *)tsd;
65
66	if ((ts->ts_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
67		return (1);
68	return (0);
69}
70
71int
72benchmark_finibatch(void *tsd)
73{
74	tsd_t 			*ts = (tsd_t *)tsd;
75
76	(void) close(ts->ts_fd);
77	return (0);
78}
79
80int
81benchmark(void *tsd, result_t *res)
82{
83	int			i;
84	tsd_t			*ts = (tsd_t *)tsd;
85	int			opt;
86
87	res->re_errors = 0;
88
89	for (i = 0; i < lm_optB; i++) {
90		opt = 1 & i;
91		if (setsockopt(ts->ts_fd, IPPROTO_TCP, TCP_NODELAY,
92		    &opt, sizeof (int)) == -1) {
93			res->re_errors ++;
94		}
95	}
96	res->re_count += lm_optB;
97
98	return (0);
99}
100