bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/*
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * CDDL HEADER START
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * The contents of this file are subject to the terms
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * of the Common Development and Distribution License
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * (the "License"). You may not use this file except
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * in compliance with the License.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * You can obtain a copy of the license at
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * src/OPENSOLARIS.LICENSE
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * or http://www.opensolaris.org/os/licensing.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * See the License for the specific language governing
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * permissions and limitations under the License.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * When distributing Covered Code, include this CDDL
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * HEADER in each file and include the License file at
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * usr/src/OPENSOLARIS.LICENSE. If applicable,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * add the following below this CDDL HEADER, with the
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * fields enclosed by brackets "[]" replaced with your
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * own identifying information: Portions Copyright [yyyy]
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * [name of copyright owner]
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * CDDL HEADER END
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch */
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch/*
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * Use is subject to license terms.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch */
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <sys/types.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <sys/socket.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <netinet/in.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <netinet/tcp.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <arpa/inet.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <netdb.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <string.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <unistd.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <stdlib.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <stdio.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <fcntl.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <errno.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include <sys/poll.h>
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#include "libmicro.h"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch#define FIRSTPORT 12345
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschtypedef struct {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int ts_once;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int *ts_lsns;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int *ts_accs;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int *ts_cons;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch struct sockaddr_in *ts_adds;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch} tsd_t;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstatic int opta = 0;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstatic int optc = 0;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstatic struct hostent *host;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_init()
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch lm_defB = 256;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch lm_tsdsize = sizeof (tsd_t);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) sprintf(lm_optstr, "ac");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) sprintf(lm_usage,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch " [-a] (measure accept() only)\n"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch " [-c] (measure connect() only)\n"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "notes: measures connect()/accept()\n");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch/*ARGSUSED*/
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_optswitch(int opt, char *optarg)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch switch (opt) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch case 'a':
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch opta = 1;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch break;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch case 'c':
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch optc = 1;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch break;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch default:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (-1);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (opta && optc) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) printf("warning: -a overrides -c\n");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch optc = 0;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (0);
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_initrun()
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) setfdlimit(3 * lm_optB * lm_optT + 10);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_initbatch_once(void *tsd)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch tsd_t *ts = (tsd_t *)tsd;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int i, j;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int errors = 0;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_lsns == NULL) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_accs = (int *)malloc(lm_optB * sizeof (int));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_accs == NULL) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_cons = (int *)malloc(lm_optB * sizeof (int));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_cons == NULL) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_adds =
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (struct sockaddr_in *)malloc(lm_optB *
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sizeof (struct sockaddr_in));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_accs == NULL) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch j = FIRSTPORT;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for (i = 0; i < lm_optB; i++) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_lsns[i] = socket(AF_INET, SOCK_STREAM, 0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_lsns[i] == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("socket");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch /*
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * make accept socket non-blocking so in case of errors
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch * we don't hang
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch */
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (fcntl(ts->ts_lsns[i], F_SETFL, O_NDELAY) == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("fcntl");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if ((host = gethostbyname("localhost")) == NULL) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for (;;) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) memset(&ts->ts_adds[i], 0,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sizeof (struct sockaddr_in));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_adds[i].sin_family = AF_INET;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_adds[i].sin_port = htons(j++);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch host->h_addr_list[0], sizeof (struct in_addr));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (bind(ts->ts_lsns[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (struct sockaddr *)&ts->ts_adds[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sizeof (struct sockaddr_in)) == 0) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch break;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (errno != EADDRINUSE) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (listen(ts->ts_lsns[i], 5) == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("listen");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (errors);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_initbatch(void *tsd)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch tsd_t *ts = (tsd_t *)tsd;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int i;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int errors = 0;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int result;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_once++ == 0) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (errors += benchmark_initbatch_once(tsd) == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (-1);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for (i = 0; i < lm_optB; i++) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ts->ts_cons[i] = socket(AF_INET, SOCK_STREAM, 0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (ts->ts_cons[i] == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("init:socket");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (fcntl(ts->ts_cons[i], F_SETFL, O_NDELAY) == -1) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("init:fcntl");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (opta) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch result = connect(ts->ts_cons[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (struct sockaddr *)&ts->ts_adds[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sizeof (struct sockaddr_in));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if ((result == -1) && (errno != EINPROGRESS)) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("init:connect");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (errors);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark(void *tsd, result_t *res)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch tsd_t *ts = (tsd_t *)tsd;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int i;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int result;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch struct sockaddr_in addr;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch socklen_t size;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for (i = 0; i < lm_optB; i++) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (!opta) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch again:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch result = connect(ts->ts_cons[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (struct sockaddr *)&ts->ts_adds[i],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sizeof (struct sockaddr_in));
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (result != 0 && errno != EISCONN) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (errno == EINPROGRESS) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch struct pollfd pollfd;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (optc)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch continue;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch pollfd.fd = ts->ts_cons[i];
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch pollfd.events = POLLOUT;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (poll(&pollfd, 1, -1) == 1)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch goto again;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch res->re_errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("benchmark:connect");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch continue;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch }
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (!optc) {
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch size = sizeof (struct sockaddr);
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch for (;;) {
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch struct pollfd pollfd;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch result = accept(ts->ts_lsns[i],
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch (struct sockaddr *)&addr, &size);
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (result > 0 || (result == -1 &&
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch errno != EAGAIN))
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch break;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch pollfd.fd = ts->ts_lsns[i];
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch pollfd.events = POLLIN;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (poll(&pollfd, 1, -1) != 1)
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch break;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch }
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch ts->ts_accs[i] = result;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (result == -1) {
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch res->re_errors ++;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch perror("benchmark:accept");
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch continue;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch }
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch res->re_count = i;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschbenchmark_finibatch(void *tsd)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch{
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch tsd_t *ts = (tsd_t *)tsd;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch int i;
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch for (i = 0; i < lm_optB; i++) {
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch if (!optc) {
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch (void) close(ts->ts_accs[i]);
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch }
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch (void) close(ts->ts_cons[i]);
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch }
2b1933b133f3e3571b32fa56fb823b4a6f9aab57Stephan Bosch
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch return (0);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch