fcntl_ndelay.c revision 0
4N/A/*
4N/A * CDDL HEADER START
4N/A *
4N/A * The contents of this file are subject to the terms
4N/A * of the Common Development and Distribution License
4N/A * (the "License"). You may not use this file except
4N/A * in compliance with the License.
4N/A *
4N/A * You can obtain a copy of the license at
4N/A * src/OPENSOLARIS.LICENSE
4N/A * or http://www.opensolaris.org/os/licensing.
4N/A * See the License for the specific language governing
4N/A * permissions and limitations under the License.
4N/A *
4N/A * When distributing Covered Code, include this CDDL
4N/A * HEADER in each file and include the License file at
4N/A * usr/src/OPENSOLARIS.LICENSE. If applicable,
4N/A * add the following below this CDDL HEADER, with the
4N/A * fields enclosed by brackets "[]" replaced with your
4N/A * own identifying information: Portions Copyright [yyyy]
4N/A * [name of copyright owner]
4N/A *
4N/A * CDDL HEADER END
4N/A */
4N/A
4N/A/*
4N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
4N/A * Use is subject to license terms.
4N/A */
4N/A
4N/A#ifdef __sun
4N/A#pragma ident "@(#)fcntl_ndelay.c 1.5 05/08/04 SMI"
4N/A#endif
4N/A
4N/A/*
4N/A * measures O_NDELAY on socket
4N/A */
4N/A
4N/A#include <sys/types.h>
4N/A#include <sys/socket.h>
4N/A#include <fcntl.h>
4N/A#include <netinet/in.h>
4N/A#include <netinet/tcp.h>
4N/A#include <arpa/inet.h>
4N/A#include <netdb.h>
4N/A#include <string.h>
4N/A#include <unistd.h>
4N/A#include <stdlib.h>
4N/A#include <stdio.h>
4N/A#include <errno.h>
4N/A
4N/A#include "libmicro.h"
4N/A
4N/Astatic int fd = -1;
4N/A
4N/Aint
4N/Abenchmark_init()
4N/A{
4N/A (void) sprintf(lm_usage,
4N/A "notes: measures F_GETFL/F_SETFL O_NDELAY on socket\n");
4N/A
4N/A lm_tsdsize = 0;
4N/A
4N/A return (0);
4N/A}
4N/A
4N/Aint
4N/Abenchmark_initrun()
4N/A{
4N/A fd = socket(AF_INET, SOCK_STREAM, 0);
4N/A if (fd == -1) {
4N/A perror("socket");
4N/A exit(1);
4N/A }
4N/A
4N/A return (0);
4N/A}
4N/A
4N/A/*ARGSUSED*/
4N/Aint
4N/Abenchmark(void *tsd, result_t *res)
4N/A{
4N/A int i;
4N/A int flags;
4N/A
4N/A for (i = 0; i < lm_optB; i += 4) {
4N/A if (fcntl(fd, F_GETFL, &flags) < 0)
4N/A res->re_errors++;
4N/A flags |= O_NDELAY;
4N/A
4N/A if (fcntl(fd, F_SETFL, &flags) < 0)
4N/A res->re_errors++;
4N/A
4N/A if (fcntl(fd, F_GETFL, &flags) < 0)
4N/A res->re_errors++;
4N/A flags &= ~O_NDELAY;
4N/A
4N/A if (fcntl(fd, F_SETFL, &flags) < 0)
4N/A res->re_errors++;
4N/A }
4N/A res->re_count = i;
4N/A
4N/A return (0);
4N/A}
4N/A