summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorjsorg71 <jsorg71>2009-09-05 03:29:43 +0000
committerjsorg71 <jsorg71>2009-09-05 03:29:43 +0000
commit2a7c40dad83d2a1a90c795ba3f58edf672d25fe3 (patch)
treefc8a0534bd869ccba95a6e111c9d6f2c2b799ed6 /common
parent8a8b57153d165c48a3d6eed4e944dc37a8841cde (diff)
downloadxrdp-proprietary-2a7c40dad83d2a1a90c795ba3f58edf672d25fe3.tar.gz
xrdp-proprietary-2a7c40dad83d2a1a90c795ba3f58edf672d25fe3.zip
add unix socket to trans
Diffstat (limited to 'common')
-rw-r--r--common/os_calls.c17
-rw-r--r--common/os_calls.h2
-rw-r--r--common/trans.c61
-rw-r--r--common/trans.h3
4 files changed, 72 insertions, 11 deletions
diff --git a/common/os_calls.c b/common/os_calls.c
index eff577c7..f530d002 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -387,6 +387,23 @@ g_tcp_connect(int sck, const char* address, const char* port)
}
/*****************************************************************************/
+/* returns error, zero is good */
+int APP_CC
+g_tcp_local_connect(int sck, const char* port)
+{
+#if defined(_WIN32)
+ return -1;
+#else
+ struct sockaddr_un s;
+
+ memset(&s, 0, sizeof(struct sockaddr_un));
+ s.sun_family = AF_UNIX;
+ strcpy(s.sun_path, port);
+ return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_un));
+#endif
+}
+
+/*****************************************************************************/
int APP_CC
g_tcp_set_non_blocking(int sck)
{
diff --git a/common/os_calls.h b/common/os_calls.h
index 4c727f66..4296f172 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -64,6 +64,8 @@ g_tcp_close(int sck);
int APP_CC
g_tcp_connect(int sck, const char* address, const char* port);
int APP_CC
+g_tcp_local_connect(int sck, const char* port);
+int APP_CC
g_tcp_force_send(int sck, char* data, int len);
int APP_CC
g_tcp_force_recv(int sck, char* data, int len);
diff --git a/common/trans.c b/common/trans.c
index 47df3523..d83ea7f6 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -54,6 +54,11 @@ trans_delete(struct trans* self)
free_stream(self->in_s);
free_stream(self->out_s);
g_tcp_close(self->sck);
+ if (self->listen_filename != 0)
+ {
+ g_file_delete(self->listen_filename);
+ g_free(self->listen_filename);
+ }
g_free(self);
}
@@ -283,9 +288,23 @@ trans_connect(struct trans* self, const char* server, const char* port,
{
g_tcp_close(self->sck);
}
- self->sck = g_tcp_socket();
- g_tcp_set_non_blocking(self->sck);
- error = g_tcp_connect(self->sck, server, port);
+ if (self->mode == 1) /* tcp */
+ {
+ self->sck = g_tcp_socket();
+ g_tcp_set_non_blocking(self->sck);
+ error = g_tcp_connect(self->sck, server, port);
+ }
+ else if (self->mode == 2) /* unix socket */
+ {
+ self->sck = g_tcp_local_socket();
+ g_tcp_set_non_blocking(self->sck);
+ error = g_tcp_local_connect(self->sck, port);
+ }
+ else
+ {
+ self->status = 0;
+ return 1;
+ }
if (error == -1)
{
if (g_tcp_last_error_would_block(self->sck))
@@ -312,15 +331,37 @@ trans_listen(struct trans* self, char* port)
{
g_tcp_close(self->sck);
}
- self->sck = g_tcp_socket();
- g_tcp_set_non_blocking(self->sck);
- if (g_tcp_bind(self->sck, port) == 0)
+ if (self->mode == 1) /* tcp */
{
- if (g_tcp_listen(self->sck) == 0)
+ self->sck = g_tcp_socket();
+ g_tcp_set_non_blocking(self->sck);
+ if (g_tcp_bind(self->sck, port) == 0)
{
- self->status = 1; /* ok */
- self->type1 = 1; /* listener */
- return 0;
+ if (g_tcp_listen(self->sck) == 0)
+ {
+ self->status = 1; /* ok */
+ self->type1 = 1; /* listener */
+ return 0;
+ }
+ }
+ }
+ else if (self->mode == 2) /* unix socket */
+ {
+ g_free(self->listen_filename);
+ self->listen_filename = 0;
+ g_file_delete(port);
+ self->sck = g_tcp_local_socket();
+ g_tcp_set_non_blocking(self->sck);
+ if (g_tcp_local_bind(self->sck, port) == 0)
+ {
+ self->listen_filename = g_strdup(port);
+ if (g_tcp_listen(self->sck) == 0)
+ {
+ g_chmod_hex(port, 0xffff);
+ self->status = 1; /* ok */
+ self->type1 = 1; /* listener */
+ return 0;
+ }
}
}
return 1;
diff --git a/common/trans.h b/common/trans.h
index 4df515da..8abb8afd 100644
--- a/common/trans.h
+++ b/common/trans.h
@@ -37,7 +37,7 @@ typedef int (*ttrans_conn_in)(struct trans* self, struct trans* new_self);
struct trans
{
tbus sck;
- int mode; /* tcp, shared memory, pipes */
+ int mode; /* 1 tcp, 2 unix socket */
int status;
int type1; /* 1 listener 2 server 3 client */
ttrans_data_in trans_data_in;
@@ -46,6 +46,7 @@ struct trans
int header_size;
struct stream* in_s;
struct stream* out_s;
+ char* listen_filename;
};
struct trans* APP_CC