作者wens.bbs@processor.tfcis.org ( ) 看板: plan
標題Re: [修正] 在 BBS 上設定轉信
時間動力核心 (2004/05/01 Sat 20:58:40) Updated: 2004/10/23
今天測試過了 可以用
TIMEOUT的單位是秒
若TIMEOUT秒後未能連線 就連線失敗
這比等核心timeout要來的快
: bbslink.c 新增這一段於 inetclient() 前面
#include <setjmp.h>
static sigjmp_buf timeout_env;
static void
abort_timeout(sig)
int sig;
{
siglongjmp(timeout_env, -1);
}
: bbslink.c:inetclient()
/* Allocate a socket */
fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd < 0)
return -1;
+ signal(SIGALRM, abort_timeout);
+ if (sigsetjmp(timeout_env, 1) != 0)
+ {
+ signal(SIGALRM, SIG_DFL);
+ return -1;
+ }
+ alarm(10); /* 10 秒後 timeout */
/* Connect the socket to the server */
if (connect(fd, (struct sockaddr *) & sin, sizeof(sin)) < 0)
{
close(fd);
return -1;
}
+ signal(SIGALRM, SIG_DFL);
+ alarm(0);
return fd;
--
╭┼ Origin: Maple-itoc˙動力核心 processor.tfcis.org
┼╯ Author: wens 從 220-134-246-97.hinet-ip.hinet.net 發表