On Sun, Nov 16, 2014 at 17:01, Dirk Engling wrote:
> Now I noticed that libtls's tls_client.c only allows for tls_connect
> which creates blocking sockets only or tls_connect_socket which appears
> to use the underlying socket's blocking state. The socket itself is
> opaque to me, so that I can not call select() to see if data is pending
> there which is a surprisingly missing feature, considering tls_read
> blocking non-abort-ably in SSL_read.

To address just one small point, I think it's time to add an accessor
for the socket. This will let you select() on it, set it non-blocking,
set the window size, set nagle, etc. I'd much rather not add a whole
family of functions for that. This is seems a reasonable exception to
our principle of keeping things opaque. The underlying socket should
be revealed.

This adds tls_get_fds(ctx, readfd, writefd). We already support
separate read and write fds (even though we don't save them in that
case!), so I think it's best to make this function future ready, even
though today it relies on ctx->socket being set.

Index: tls.c
===================================================================
RCS file: /cvs/src/lib/libtls/tls.c,v
retrieving revision 1.1
diff -u -p -r1.1 tls.c
--- tls.c       31 Oct 2014 13:46:17 -0000      1.1
+++ tls.c       16 Nov 2014 23:07:37 -0000
@@ -225,6 +225,18 @@ tls_reset(struct tls *ctx)
 }
 
 int
+tls_get_fds(struct tls *ctx, int *readfd, int *writefd)
+{
+       if (ctx->socket == -1)
+               return -1;
+
+       *readfd = ctx->socket;
+       *writefd = ctx->socket;
+
+       return 0;
+}
+
+int
 tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen)
 {
        int ret, ssl_err;
Index: tls.h
===================================================================
RCS file: /cvs/src/lib/libtls/tls.h,v
retrieving revision 1.2
diff -u -p -r1.2 tls.h
--- tls.h       2 Nov 2014 14:45:05 -0000       1.2
+++ tls.h       16 Nov 2014 23:08:06 -0000
@@ -71,6 +71,7 @@ int tls_connect_fds(struct tls *ctx, int
 int tls_connect_socket(struct tls *ctx, int s, const char *hostname);
 int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen);
 int tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen);
+int tls_get_fds(struct tls *ctx, int *readfd, int *writefd);
 int tls_close(struct tls *ctx);
 
 #endif /* HEADER_TLS_H */

Reply via email to