summaryrefslogtreecommitdiff
path: root/sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sockets.c b/sockets.c
index 0f78b21..c5ea41f 100644
--- a/sockets.c
+++ b/sockets.c
@@ -165,3 +165,23 @@ void configure_context(SSL_CTX *ctx, char *certfile, char *keyfile) {
exit(EXIT_FAILURE);
}
}
+
+// Read from a socket, whether or not using TLS
+int sockread(SSL *fd, char *buf, int bufsize, int tls) {
+ if (tls) {
+ return SSL_read(fd, buf, bufsize);
+ } else {
+ // Cast the supposed SSL *fd to a long int if we're not using TLS
+ return recv((long int)fd, buf, bufsize, 0);
+ }
+}
+
+// Write to a socket, whether or not using TLS
+int socksend(SSL *fd, char *buf, int bufsize, int tls) {
+ if (tls) {
+ return SSL_write(fd, buf, bufsize);
+ } else {
+ // Cast the supposed SSL *fd to a long int if we're not using TLS
+ return send((long int)fd, buf, bufsize, 0);
+ }
+}