ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtdaemon.C
Revision: 1.2
Committed: Mon Nov 24 19:52:16 2003 UTC (20 years, 6 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -17 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <unistd.h>
2 #include <stdint.h>
3 #include <cstdlib>
4 #include <cstring>
5
6 #include "rxvtdaemon.h"
7
8 const char *rxvt_connection::unix_sockname ()
9 {
10 return "/tmp/rxvtd~";
11 }
12
13 void rxvt_connection::send (const char *data, int len)
14 {
15 uint8_t s[2];
16
17 s[0] = len >> 8; s[1] = len;
18
19 write (fd, s, 2);
20 write (fd, data, len);
21 }
22
23 void rxvt_connection::send (const char *data)
24 {
25 send (data, strlen (data));
26 }
27
28 bool rxvt_connection::recv (auto_str &data, int *len)
29 {
30 uint8_t s[2];
31 int l;
32
33 if (read (fd, s, 2) != 2)
34 return false;
35
36 l = (s[0] << 8) + s[1];
37 if (l > 4096)
38 return false;
39
40 if (len)
41 *len = l;
42
43 data = new char[l + 1];
44
45 if (!data)
46 return false;
47
48 if (read (fd, data, l) != l)
49 return false;
50
51 data[l] = 0;
52
53 return true;
54 }
55
56 void rxvt_connection::send (int data)
57 {
58 uint8_t s[4];
59
60 s[0] = data >> 24; s[1] = data >> 16; s[0] = data >> 8; s[1] = data;
61
62 write (fd, s, 4);
63 }
64
65 bool rxvt_connection::recv (int &data)
66 {
67 uint8_t s[4];
68
69 if (read (fd, s, 4) != 4)
70 return false;
71
72 data = (((((s[0] << 8) | s[1]) << 8) | s[2]) << 8) | s[3];
73
74 return true;
75 }
76
77
78