connect超时:
目前各平台通用的设置socket connect超时的办法是通过select(),具体方法如下:
1.建立socket;
2.将该socket设置为非阻塞模式;
3.调用connect();
4.使用select()检查该socket描述符是否可写;
5.根据select()返回的结果判断connect()结果;
6.将socket设回阻塞模式。
下面给出的是我写的client程序(已经编译通过):
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <unistd.h>
#include <asm/ioctls.h>
#define MAXDATASIZE 4926
int detect_imap(const char *server ,char *protocol,unsigned short port)
{
int sockfd,n