try to connect more than once
This commit is contained in:
parent
d9516e6837
commit
b10851d327
48
xup/xup.c
48
xup/xup.c
@ -129,6 +129,7 @@ lib_mod_connect(struct mod* mod)
|
|||||||
int error;
|
int error;
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
|
int index;
|
||||||
struct stream* s;
|
struct stream* s;
|
||||||
char con_port[256];
|
char con_port[256];
|
||||||
|
|
||||||
@ -157,12 +158,47 @@ lib_mod_connect(struct mod* mod)
|
|||||||
g_sprintf(con_port, "%s", mod->port);
|
g_sprintf(con_port, "%s", mod->port);
|
||||||
mod->sck = g_tcp_socket();
|
mod->sck = g_tcp_socket();
|
||||||
mod->sck_obj = g_create_wait_obj_from_socket(mod->sck, 0);
|
mod->sck_obj = g_create_wait_obj_from_socket(mod->sck, 0);
|
||||||
|
g_tcp_set_non_blocking(mod->sck);
|
||||||
|
g_tcp_set_no_delay(mod->sck);
|
||||||
mod->sck_closed = 0;
|
mod->sck_closed = 0;
|
||||||
error = g_tcp_connect(mod->sck, mod->ip, con_port);
|
i = 0;
|
||||||
if (error == 0)
|
while (1)
|
||||||
{
|
{
|
||||||
g_tcp_set_non_blocking(mod->sck);
|
mod->server_msg(mod, "connecting...", 0);
|
||||||
g_tcp_set_no_delay(mod->sck);
|
error = g_tcp_connect(mod->sck, mod->ip, con_port);
|
||||||
|
if (error == -1)
|
||||||
|
{
|
||||||
|
if (g_tcp_last_error_would_block(mod->sck))
|
||||||
|
{
|
||||||
|
error = 0;
|
||||||
|
index = 0;
|
||||||
|
while (!g_tcp_can_send(mod->sck, 100))
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
if ((index >= 30) || mod->server_is_term(mod))
|
||||||
|
{
|
||||||
|
mod->server_msg(mod, "connect timeout", 0);
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mod->server_msg(mod, "connect error", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
if (i >= 4)
|
||||||
|
{
|
||||||
|
mod->server_msg(mod, "connect problem, giving up", 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_sleep(250);
|
||||||
}
|
}
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
{
|
{
|
||||||
@ -191,6 +227,10 @@ lib_mod_connect(struct mod* mod)
|
|||||||
LIB_DEBUG(mod, "out lib_mod_connect error");
|
LIB_DEBUG(mod, "out lib_mod_connect error");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mod->server_msg(mod, "connected ok", 0);
|
||||||
|
}
|
||||||
LIB_DEBUG(mod, "out lib_mod_connect");
|
LIB_DEBUG(mod, "out lib_mod_connect");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user