summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2015-08-18 21:10:23 -0700
committerJay Sorg <jay.sorg@gmail.com>2015-08-18 21:10:23 -0700
commit6384bae1e77d7fe1d4ee55d2e710009bcd4811dc (patch)
tree1700f10e7caf1fccd7a513500627e5a2708340c4 /common
parentbfe69badc338c5978555aa98a0047f3707b45be4 (diff)
downloadxrdp-proprietary-6384bae1e77d7fe1d4ee55d2e710009bcd4811dc.tar.gz
xrdp-proprietary-6384bae1e77d7fe1d4ee55d2e710009bcd4811dc.zip
common: changes to trans for timeout
Diffstat (limited to 'common')
-rw-r--r--common/trans.c76
1 files changed, 72 insertions, 4 deletions
diff --git a/common/trans.c b/common/trans.c
index 31da1325..973bafaa 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -649,29 +649,88 @@ trans_connect(struct trans *self, const char *server, const char *port,
int timeout)
{
int error;
+ int now;
+ int start_time;
+
+ start_time = g_time3();
if (self->sck != 0)
{
g_tcp_close(self->sck);
+ self->sck = 0;
}
if (self->mode == TRANS_MODE_TCP) /* tcp */
{
self->sck = g_tcp_socket();
if (self->sck < 0)
+ {
+ self->status = TRANS_STATUS_DOWN;
return 1;
-
+ }
g_tcp_set_non_blocking(self->sck);
- error = g_tcp_connect(self->sck, server, port);
+ while (1)
+ {
+ error = g_tcp_connect(self->sck, server, port);
+ if (error == 0)
+ {
+ break;
+ }
+ else
+ {
+ if (timeout < 1)
+ {
+ self->status = TRANS_STATUS_DOWN;
+ return 1;
+ }
+ now = g_time3();
+ if (now - start_time < timeout)
+ {
+ g_sleep(timeout / 5);
+ }
+ else
+ {
+ self->status = TRANS_STATUS_DOWN;
+ return 1;
+ }
+ }
+ }
}
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
{
self->sck = g_tcp_local_socket();
if (self->sck < 0)
+ {
+ self->status = TRANS_STATUS_DOWN;
return 1;
-
+ }
g_tcp_set_non_blocking(self->sck);
- error = g_tcp_local_connect(self->sck, port);
+ while (1)
+ {
+ error = g_tcp_local_connect(self->sck, port);
+ if (error == 0)
+ {
+ break;
+ }
+ else
+ {
+ if (timeout < 1)
+ {
+ self->status = TRANS_STATUS_DOWN;
+ return 1;
+ }
+ now = g_time3();
+ if (now - start_time < timeout)
+ {
+ g_sleep(timeout / 5);
+ }
+ else
+ {
+ self->status = TRANS_STATUS_DOWN;
+ return 1;
+ }
+ }
+ }
}
else
{
@@ -683,6 +742,15 @@ trans_connect(struct trans *self, const char *server, const char *port,
{
if (g_tcp_last_error_would_block(self->sck))
{
+ now = g_time3();
+ if (now - start_time < timeout)
+ {
+ timeout = timeout - (now - start_time);
+ }
+ else
+ {
+ timeout = 0;
+ }
if (g_tcp_can_send(self->sck, timeout))
{
self->status = TRANS_STATUS_UP; /* ok */