shlist

share and manage lists between multiple people
Log | Files | Refs

commit 4d6d0c9d28e977744baddcf8cfa5fe1d5f0bff19
parent 2771af32c895f30cb4a5c757e701c68ce898ffe9
Author: kyle <kyle@0x30.net>
Date:   Sat, 23 Jan 2016 11:30:17 -0700

sl: handle large writes properly

- the underlying ssl layer can only send ~16 KB at once
- make sure to loop if we have more data than that to send
- add a test that does a large request

Diffstat:
Mserver/sl | 17++++++++++-------
Aserver/tests/large_response/Makefile | 3+++
Aserver/tests/large_response/test.pl | 21+++++++++++++++++++++
3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/server/sl b/server/sl @@ -172,14 +172,17 @@ sub send_msg { sub send_all { my ($socket, $bytes, $bytes_total) = @_; - my $bytes_written = $socket->syswrite($bytes); + my $bytes_written = 0; + while ($bytes_total) { + my $wrote = $socket->syswrite($bytes, $bytes_total, $bytes_written); - if (!defined $bytes_written) { - $log->print("error: write failed: $!\n"); - exit 0; - } elsif ($bytes_written != $bytes_total) { - $log->print("error: wrote $bytes_written instead of $bytes_total bytes\n"); - exit 0; + unless (defined $bytes_written) { + $log->print("error: write failed: $!\n"); + exit 0; + } + + $bytes_total -= $wrote; + $bytes_written += $wrote; } return; diff --git a/server/tests/large_response/Makefile b/server/tests/large_response/Makefile @@ -0,0 +1,3 @@ +DIFF_MOD=none + +include ../test.mk diff --git a/server/tests/large_response/test.pl b/server/tests/large_response/test.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -I../ +use strict; +use warnings; +use client; +use test; + +# Test that large responses > 16384 bytes work as the underlying ssl layer can +# only handle that much data at a time + +my $A = client->new(); +for (1..500) { + $A->list_add($_); +} + +# The response to this lists_get request clocks in at ~59 KB +my $count = 0; +for my $list ($A->lists_get()) { + $count += 1; + fail_msg_ne "$count", $list->{name}; +} +fail_num_ne 'total lists different', $count, 500;