/* * tcpcli a very simple TCP client for benchmarking * Copyright (c) 2006 Michal Trojnara * All Rights Reserved * * Version: 1.00 * Date: 2006.12.17 * * Author: Michal Trojnara * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include #include #include #define NUM_THREADS 1 #define NUM_RETRIES 10000 int port_number=50000; int false=0, true=1; void connection(void) { struct sockaddr_in addr; int fd, rc; char c; fd=socket(AF_INET, SOCK_STREAM, 0); memset(&addr, 0, sizeof(addr)); addr.sin_family=AF_INET; addr.sin_addr.s_addr=htonl(INADDR_LOOPBACK); addr.sin_port=htons(port_number); rc=connect(fd, (struct sockaddr *)&addr, sizeof(addr)); if(rc) { /* error */ close(fd); perror("connect"); // printf("Thread finished: error\n"); pthread_exit(&true); } rc=read(fd, &c, 1); /* read a single byte */ close(fd); if(rc==1) /* ok */ return; if(rc) /* error */ perror("read"); else /* eof */ fprintf(stderr, "read: Unexpected close\n"); // printf("Thread finished: error\n"); pthread_exit(&true); } void *thread_proc(void *arg) { int i; // printf("Thread started\n"); for(i=0; i