summaryrefslogtreecommitdiffstats
path: root/common/trans.c
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2013-09-23 12:16:52 -0700
committerJay Sorg <jay.sorg@gmail.com>2013-09-23 12:16:52 -0700
commitdfd78c722b738e8db4c096393b6ecf0e26435f40 (patch)
treea2d38654b84ead032388820b2d9fc9810d7c5cf6 /common/trans.c
parentdb71bc5d8b7841dee476bee228eadf009cec710f (diff)
downloadxrdp-proprietary-dfd78c722b738e8db4c096393b6ecf0e26435f40.tar.gz
xrdp-proprietary-dfd78c722b738e8db4c096393b6ecf0e26435f40.zip
chansrv: fix for deadlock
Diffstat (limited to 'common/trans.c')
-rw-r--r--common/trans.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/common/trans.c b/common/trans.c
index 8313b606..408b4a7e 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -291,6 +291,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
size = (int)(out_s->end - out_s->data);
total = 0;
+ self->in_write = 1;
while (total < size)
{
sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0);
@@ -308,6 +309,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
{
/* term */
self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
return 1;
}
}
@@ -317,6 +319,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
{
/* error */
self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
return 1;
}
}
@@ -324,6 +327,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
{
/* error */
self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
return 1;
}
else
@@ -331,6 +335,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
total = total + sent;
}
}
+ self->in_write = 0;
return 0;
}
@@ -344,6 +349,84 @@ trans_force_write(struct trans *self)
/*****************************************************************************/
int APP_CC
+trans_write_check(struct trans* self, int timeout)
+{
+ int size;
+ int total;
+ int sent;
+ int error;
+ tbus robjs[1];
+ tbus wobjs[1];
+ struct stream *out_s;
+
+ if (self->status != TRANS_STATUS_UP)
+ {
+ return 1;
+ }
+
+ out_s = self->out_s;
+
+ size = (int)(out_s->end - out_s->data);
+ total = 0;
+
+ self->in_write = 1;
+ while (total < size)
+ {
+ robjs[0] = self->sck;
+ wobjs[0] = self->sck;
+ error = g_obj_wait(robjs, 1, wobjs, 1, timeout);
+ if (error != 0)
+ {
+ /* error */
+ self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
+ return 1;
+ }
+
+ if (!g_tcp_can_send(self->sck, 0))
+ {
+ trans_check_wait_objs(self);
+ continue;
+ }
+
+ sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0);
+
+ if (sent == -1)
+ {
+ if (g_tcp_last_error_would_block(self->sck))
+ {
+ if (!g_tcp_can_send(self->sck, 10))
+ {
+ /* check for term here */
+ }
+ }
+ else
+ {
+ /* error */
+ self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
+ return 1;
+ }
+ }
+ else if (sent == 0)
+ {
+ /* error */
+ self->status = TRANS_STATUS_DOWN;
+ self->in_write = 0;
+ return 1;
+ }
+ else
+ {
+ total = total + sent;
+ }
+ }
+ self->in_write = 0;
+
+ return 0;
+}
+
+/*****************************************************************************/
+int APP_CC
trans_connect(struct trans *self, const char *server, const char *port,
int timeout)
{