#include #include #include #include #include #include #include #include /* ** ZABBIX ** Copyright (C) 2000-2005 SIA Zabbix ** ** 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. **/ #define NUM 256 #define ZBXPOOL struct zbxpool_type ZBXPOOL { char ip[128]; int port; int socket; int status; /* 0 - not connected, 1 - connected, 2 - wrote data */ }; ZBXPOOL pool[NUM]; int s; struct pollfd poll_cli[NUM]; void init_pool() { int i; for(i=0;ih_addr))->s_addr; servaddr_in.sin_port=htons(port); s=socket(AF_INET,SOCK_STREAM,0); if(s == -1) { perror("socket() failed"); } if(fcntl(s, F_SETFL, O_NONBLOCK) == -1) { perror("fcntl() failed\n"); exit(-1); } retval = connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); if(retval == 0) { printf("Socket connected immediately"); } else if(retval == -1) { if(errno == EINPROGRESS) { printf("Connection in progress\n"); } else { perror("connect"); exit(-1); } } poll_cli[i].fd = s; poll_cli[i].events = POLLOUT; } wait_connect(); }