aboutsummaryrefslogtreecommitdiffstats
path: root/tcp.c
diff options
context:
space:
mode:
authorGustav HÃ¥llberg <gustav@gmail.com>2009-01-16 23:49:38 (GMT)
committerGustav HÃ¥llberg <gustav@gmail.com>2009-01-16 23:55:40 (GMT)
commit6f1485f772cf5671fb5f8d94026254e6f1e6a832 (patch)
tree30a35cc8ed5a9dc56dc26fd24a95aac4e7660c02 /tcp.c
parentdd89c7770b0fcd2e18c0f794ee192b2a62aebc8c (diff)
downloadpowwow-6f1485f772cf5671fb5f8d94026254e6f1e6a832.zip
powwow-6f1485f772cf5671fb5f8d94026254e6f1e6a832.tar.gz
powwow-6f1485f772cf5671fb5f8d94026254e6f1e6a832.tar.bz2
semi-properly handle IACs in MPI messages
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/tcp.c b/tcp.c
index fbb5812..f4af987 100644
--- a/tcp.c
+++ b/tcp.c
@@ -538,11 +538,10 @@ int tcp_read __P3 (int,fd, char *,buffer, int,maxsize)
return (char *)p - buffer;
}
-void tcp_raw_write __P3 (int,fd, char *,data, int,len)
+static void internal_tcp_raw_write __P3 (int,fd, const char *,data, int,len)
{
- int i;
- tcp_flush();
while (len > 0) {
+ int i;
while ((i = write(fd, data, len)) < 0 && errno == EINTR)
;
if (i < 0) {
@@ -554,6 +553,29 @@ void tcp_raw_write __P3 (int,fd, char *,data, int,len)
}
}
+void tcp_raw_write __P3 (int,fd, const char *,data, int,len)
+{
+ tcp_flush();
+ internal_tcp_raw_write(fd, data, len);
+}
+
+/* write data, escape any IACs */
+void tcp_write_escape_iac __P3 (int,fd, const char *,data, int,len)
+{
+ tcp_flush();
+
+ for (;;) {
+ const char *iac = memchr(data, IAC, len);
+ size_t l = iac ? (iac - data) + 1 : len;
+ internal_tcp_raw_write(fd, data, l);
+ if (iac == NULL)
+ return;
+ internal_tcp_raw_write(fd, iac, 1);
+ len -= l;
+ data = iac + 1;
+ }
+}
+
/*
* Send current terminal size (RFC 1073)
*/