aboutsummaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-09-04 16:05:08 +0000
committerNick Mathewson <nickm@torproject.org>2003-09-04 16:05:08 +0000
commitfd20011c263df7fa843d32a2323bff81357b5a20 (patch)
tree162072e508db0eea1be73e580752178449f66b94 /src/or/buffers.c
parent4fb92e5bf7144ec14f664913cfefb045fe813dfa (diff)
downloadtor-fd20011c263df7fa843d32a2323bff81357b5a20.tar
tor-fd20011c263df7fa843d32a2323bff81357b5a20.tar.gz
Add initial interfaces and code for TLS support. Interfaces are right; code needs work and testing.
svn:r424
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r--src/or/buffers.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 3ea26dbab..2cf313f10 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -86,6 +86,23 @@ int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, i
}
}
+int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen) {
+ int r;
+ assert(tls && *buf && buflen && buf_datalen);
+
+ if (at_most > *buflen - *buf_datalen)
+ at_most = *buflen - *buf_datalen;
+
+ if (at_most == 0)
+ return 0;
+
+ r = tor_tls_read(tls, *buf+*buf_datalen, at_most);
+ if (r<0)
+ return r;
+ *buf_datalen += r;
+ return r;
+}
+
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) {
/* push from buf onto s
@@ -127,6 +144,22 @@ int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datale
}
}
+int flush_buf_tls(tor_tls *tls, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen)
+{
+ int r;
+ assert(tls && *buf && buflen && buf_datalen);
+ if (*buf_flushlen == 0)
+ return 0;
+ r = tor_tls_write(tls, *buf, *buf_flushlen);
+ if (r < 0) {
+ return r;
+ }
+ *buf_datalen -= r;
+ *buf_flushlen -= r;
+ memmove(*buf, *buf+r, *buf_datalen);
+ return r;
+}
+
int write_to_buf(char *string, int string_len,
char **buf, int *buflen, int *buf_datalen) {