1 | #include <unistd.h> |
|
|
2 | #include <stdint.h> |
1 | #include <stdint.h> |
3 | #include <cstdlib> |
2 | #include <cstdlib> |
4 | #include <cstring> |
3 | #include <cstring> |
|
|
4 | #include <cstdio> |
|
|
5 | |
|
|
6 | #include <unistd.h> |
|
|
7 | #include <sys/utsname.h> |
|
|
8 | #include <limits.h> |
5 | |
9 | |
6 | #include "rxvtdaemon.h" |
10 | #include "rxvtdaemon.h" |
7 | |
11 | |
8 | const char *rxvt_connection::unix_sockname () |
12 | char *rxvt_connection::unix_sockname () |
9 | { |
13 | { |
10 | return "/tmp/rxvtd~"; |
14 | char name[PATH_MAX]; |
|
|
15 | char *path = getenv ("RXVT_SOCKET"); |
|
|
16 | |
|
|
17 | if (!path) |
|
|
18 | { |
|
|
19 | struct utsname u; |
|
|
20 | uname (&u); |
|
|
21 | |
|
|
22 | path = getenv ("HOME"); |
|
|
23 | snprintf (name, PATH_MAX, "%s/.rxvt-%s", |
|
|
24 | path ? path : "/tmp", |
|
|
25 | u.nodename); |
|
|
26 | |
|
|
27 | path = name; |
|
|
28 | } |
|
|
29 | |
|
|
30 | return strdup (path); |
11 | } |
31 | } |
12 | |
32 | |
13 | void rxvt_connection::send (const char *data, int len) |
33 | void rxvt_connection::send (const char *data, int len) |
14 | { |
34 | { |
15 | uint8_t s[2]; |
35 | uint8_t s[2]; |
… | |
… | |
23 | void rxvt_connection::send (const char *data) |
43 | void rxvt_connection::send (const char *data) |
24 | { |
44 | { |
25 | send (data, strlen (data)); |
45 | send (data, strlen (data)); |
26 | } |
46 | } |
27 | |
47 | |
28 | bool rxvt_connection::recv (char *&data, int *len) |
48 | bool rxvt_connection::recv (auto_str &data, int *len) |
29 | { |
49 | { |
30 | uint8_t s[2]; |
50 | uint8_t s[2]; |
31 | int l; |
51 | int l; |
32 | |
52 | |
33 | if (read (fd, s, 2) != 2) |
53 | if (read (fd, s, 2) != 2) |
… | |
… | |
51 | data[l] = 0; |
71 | data[l] = 0; |
52 | |
72 | |
53 | return true; |
73 | return true; |
54 | } |
74 | } |
55 | |
75 | |
56 | bool rxvt_connection::recv (token &data) |
|
|
57 | { |
|
|
58 | char *d; |
|
|
59 | int l; |
|
|
60 | |
|
|
61 | if (!recv (d, &l)) |
|
|
62 | return false; |
|
|
63 | |
|
|
64 | if (l < sizeof (token) - 1) |
|
|
65 | strcpy (data, d); |
|
|
66 | |
|
|
67 | delete [] d; |
|
|
68 | |
|
|
69 | return l < sizeof (token) - 1; |
|
|
70 | } |
|
|
71 | |
|
|
72 | void rxvt_connection::send (int data) |
76 | void rxvt_connection::send (int data) |
73 | { |
77 | { |
74 | uint8_t s[4]; |
78 | uint8_t s[4]; |
75 | |
79 | |
76 | s[0] = data >> 24; s[1] = data >> 16; s[0] = data >> 8; s[1] = data; |
80 | s[0] = data >> 24; s[1] = data >> 16; s[0] = data >> 8; s[1] = data; |