5
#include <sys/socket.h>
12
** Copyright (C) 2000-2005 SIA Zabbix
14
** This program is free software; you can redistribute it and/or modify
15
** it under the terms of the GNU General Public License as published by
16
** the Free Software Foundation; either version 2 of the License, or
17
** (at your option) any later version.
19
** This program is distributed in the hope that it will be useful,
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
** GNU General Public License for more details.
24
** You should have received a copy of the GNU General Public License
25
** along with this program; if not, write to the Free Software
26
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34
struct epoll_event ev;
35
struct epoll_event *events;
43
printf("Waiting for connect\n");
48
printf("epfd [%d]\n", epfd);
49
printf("NUM [%d]\n", NUM);
50
events=malloc(NUM*sizeof(struct epoll_event));
51
retval = epoll_wait(epfd, events, NUM, -1);
55
printf("Retval [%d]\n", errno);
58
printf("Retval [%d]\n", retval);
64
printf("[%d] fd [%X]\n",i,events[i].data.fd);
74
char ip[128]="127.0.0.1";
79
struct sockaddr_in servaddr_in;
84
epfd = epoll_create(NUM);
87
perror("epoll_create\n");
93
servaddr_in.sin_family=AF_INET;
98
perror("gethostbyname() failed");
101
servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
103
servaddr_in.sin_port=htons(port);
105
s=socket(AF_INET,SOCK_STREAM,0);
109
perror("socket() failed");
112
if(fcntl(s, F_SETFL, O_NONBLOCK) == -1)
114
perror("fcntl() failed\n");
118
retval = connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in));
121
printf("Socket connected immediately");
123
else if(retval == -1)
125
if(errno == EINPROGRESS)
127
// printf("Connection in progress\n");
136
// if(fcntl(s, F_SETFL, O_NONBLOCK) == -1)
138
// perror("fcntl() failed\n");
142
ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLOUT;
144
if(epoll_ctl(epfd, EPOLL_CTL_ADD, s, &ev) < 0)
146
perror("epoll_ctl, adding listenfd\n");
149
// printf("epoll_ctl ok fd [%d]\n", s);