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