Hello everyone, I have a tough problem.
Scenario: When the remote host is inaccessible, if the SDLNet_TCP_Open function is called, it will cause blocking, and the main process will be stuck for about 15 seconds.
Here is the code:
int connectServer(void) {
static int count = 0;
// 初期化が完了してなければ何もしない
if (!init_net)
return 0;
if (connectServerCounter == 0) {
char hostname[128];
short port;
// 接続をはじめた時間を記憶
start_time = SDL_GetTicks();
// ソケットはノンブロッキングになってるので、その状態でconnectする
if (getServerInfo(selectServerIndex, hostname, &port) < 0) {
count = 0;
strcpy(netprocErrmsg, NET_ERRMSG_BADNAME);
return -2;
}
if (SDLNet_ResolveHost(&serverIp, hostname, port) == -1) {
count = 0;
strcpy(netprocErrmsg, NET_ERRMSG_NOTGETADDR);
return -3;
}
// socketつくru
tcpsock = SDLNet_TCP_Open(&serverIp); **// Here, waiting about 15s ...**
if (!tcpsock) {
count = 0;
strcpy(netprocErrmsg, NET_ERRMSG_SOCKETERROR);
return -4;
}
// 1のソケットを扱うソケットセットを生成する
socketSet = SDLNet_AllocSocketSet(1);
if (!socketSet) {
count = 0;
strcpy(netprocErrmsg, NET_ERRMSG_SOCKETSETERROR);
// ほとんどの場合これは致命的なエラーであるが, 望むように処理してよい
return -5;
}
SDLNet_TCP_AddSocket(socketSet, tcpsock);
// ここまでできたらカウンタを1にする
connectServerCounter = 1;
}
…