触发connect超时事件
有关于如何触发connect超时事件,之前相当然的认为在服务器程序accpet函数前阻塞一段事件就好了,这个思路是完全错误的!
这是我犯了的一个错误,没有严格的验证自己的程序就将其发布了出来,被小组的小伙伴提问时才发现了这个问题,在这里深表歉意!!!同时也非常感谢我的哪位小伙伴!下边是那篇文章,现已更正。
代码还是以前的代码
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int timeout_connect(const char *ip, int port, int time) // 5
{
int ret = 0;
struct sockaddr_in address;
bzero(&address, sizeof(address));
addre