static void transfer_data_tls(int client, int server,
gnutls_session_t client_session,
gnutls_session_t server_session);
-static int read_from_write_to_tls(gnutls_session_t from, gnutls_session_t to);
+static int read_from_write_to_tls(gnutls_session_t from, gnutls_session_t to,
+ size_t buffer_size);
static int connect_to_host(const char *hostname, const char *port);
static void transfer_data_tls(int client, int server,
gnutls_session_t client_session,
gnutls_session_t server_session) {
+ size_t buffer_size;
+
struct pollfd fds[2];
fds[0].fd = client;
fds[0].events = POLLIN | POLLPRI | POLLHUP | POLLERR;
fds[1].events = POLLIN | POLLPRI | POLLHUP | POLLERR;
fds[1].revents = 0;
+ /* Get maximum possible buffer size. */
+ buffer_size = gnutls_record_get_max_size(client_session);
+ LOG(LOG_DEBUG, "transfer_data_tls(): suggested buffer size: %ld",
+ (long int)buffer_size);
+ if (buffer_size > gnutls_record_get_max_size(server_session)) {
+ buffer_size = gnutls_record_get_max_size(server_session);
+ }
+
for (;;) {
int result = poll(fds, 2, -1 /* no timeout */);
if (result < 0) {
/* Data available from client. */
if (fds[0].revents & POLLIN || fds[0].revents & POLLPRI) {
- if (0 != read_from_write_to_tls(client_session, server_session)) {
+ if (0 != read_from_write_to_tls(client_session, server_session,
+ buffer_size)) {
/* EOF (or other error) */
break;
}
}
/* Data available from server. */
if (fds[1].revents & POLLIN || fds[1].revents & POLLPRI) {
- if (0 != read_from_write_to_tls(server_session, client_session)) {
+ if (0 != read_from_write_to_tls(server_session, client_session,
+ buffer_size)) {
/* EOF (or other error) */
break;
}
/* Read available data from session from and write to session to. */
static int read_from_write_to_tls(gnutls_session_t from,
- gnutls_session_t to) {
- size_t size;
+ gnutls_session_t to,
+ size_t buffer_size) {
ssize_t size_read;
ssize_t size_written;
char buffer[16384];
- /* Get maximum possible buffer size. */
- size = gnutls_record_get_max_size(from);
- LOG(LOG_DEBUG, "read_from_write_to_tls(): suggested buffer size: %ld",
- (long int)size);
- if (size > gnutls_record_get_max_size(to)) {
- size = gnutls_record_get_max_size(to);
- }
- if (size > sizeof(buffer)) {
- size = sizeof(buffer);
+ if (buffer_size > sizeof(buffer)) {
+ buffer_size = sizeof(buffer);
}
LOG(LOG_DEBUG, "read_from_write_to_tls(): used buffer size: %ld",
- (long int)size);
+ (long int)buffer_size);
- size_read = gnutls_record_recv(from, buffer, size);
+ size_read = gnutls_record_recv(from, buffer, buffer_size);
if (0 > size_read) {
LOG(LOG_WARNING, "read_from_write_to_tls(): gnutls_record_recv(): %s",
gnutls_strerror((int)size_read));