ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtdaemon.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtdaemon.C (file contents):
Revision 1.9 by root, Sun Dec 25 15:30:29 2005 UTC vs.
Revision 1.13 by root, Mon Feb 20 22:42:00 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtdaemon.C 2 * File: rxvtdaemon.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
31#include <sys/utsname.h> 31#include <sys/utsname.h>
32#include <limits.h> 32#include <limits.h>
33 33
34#include "rxvtdaemon.h" 34#include "rxvtdaemon.h"
35 35
36// works around linux kernel bug, returns EAGAIN on a blocking socket
37static ssize_t
38read_ (int fd, void *buf, size_t count)
39{
40 int ret;
41
42 do
43 ret = read (fd, buf, count);
44 while (ret < 0 && errno == EAGAIN);
45
46 return ret;
47}
48
49char *rxvt_connection::unix_sockname () 36char *rxvt_connection::unix_sockname ()
50{ 37{
51 char name[PATH_MAX]; 38 char name[PATH_MAX];
52 char *path = getenv ("RXVT_SOCKET"); 39 char *path = getenv ("RXVT_SOCKET");
53 40
69 56
70void rxvt_connection::send (const char *data, int len) 57void rxvt_connection::send (const char *data, int len)
71{ 58{
72 uint8_t s[2]; 59 uint8_t s[2];
73 60
61 if (len > 65535)
62 len = 65535;
63
74 s[0] = len >> 8; s[1] = len; 64 s[0] = len >> 8; s[1] = len;
75 65
76 write (fd, s, 2); 66 write (fd, s, 2);
77 write (fd, data, len); 67 write (fd, data, len);
78} 68}
85bool rxvt_connection::recv (auto_str &data, int *len) 75bool rxvt_connection::recv (auto_str &data, int *len)
86{ 76{
87 uint8_t s[2]; 77 uint8_t s[2];
88 int l; 78 int l;
89 79
90 if (read_ (fd, s, 2) != 2) 80 if (read (fd, s, 2) != 2)
91 return false; 81 return false;
92 82
93 l = (s[0] << 8) + s[1]; 83 l = (s[0] << 8) + s[1];
94 if (l > 4096) 84 if (l > 65535)
95 return false; 85 return false;
96 86
97 if (len) 87 if (len)
98 *len = l; 88 *len = l;
99 89
100 data = new char[l + 1]; 90 data = new char[l + 1];
101 91
102 if (!data) 92 if (!data)
103 return false; 93 return false;
104 94
105 if (read_ (fd, data, l) != l) 95 if (read (fd, data, l) != l)
106 return false; 96 return false;
107 97
108 data[l] = 0; 98 data[l] = 0;
109 99
110 return true; 100 return true;
121 111
122bool rxvt_connection::recv (int &data) 112bool rxvt_connection::recv (int &data)
123{ 113{
124 uint8_t s[4]; 114 uint8_t s[4];
125 115
126 if (read_ (fd, s, 4) != 4) 116 if (read (fd, s, 4) != 4)
127 return false; 117 return false;
128 118
129 data = (((((s[0] << 8) | s[1]) << 8) | s[2]) << 8) | s[3]; 119 data = (((((s[0] << 8) | s[1]) << 8) | s[2]) << 8) | s[3];
130 120
131 return true; 121 return true;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines