Package list libpoe-component-sslify-perl / 57b6383
remove magic from substr and reduce copying of strings Apocalypse 7 years ago
2 changed file(s) with 6 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 Revision history for {{$dist->name}}
11
22 {{$NEXT}}
3 Reduce memory usage and speedup writing large strings by avoiding substr magic
34
45 1.011 2014-11-14T03:06:48Z UTC
56 - Tweak the testsuite thanks to CPANTesters!
141141 # Write some stuff to the socket
142142 sub WRITE {
143143 # Get ourself + buffer + length + offset to write
144 my( $self, $buf, $len, $offset ) = @_;
144 my( $self, $len, $offset ) = ( $_[0], $_[2], $_[3] );
145 my $buf = \$_[1]; # don't copy!
145146
146147 # Check the status of the SSL handshake
147148 if ( ! $self->{'ssl_started'} ) {
158159 # seems like the same thing happened to https://www.mail-archive.com/openssl-users@openssl.org/msg28151.html
159160 $len = 16_384 if $len > 16_384;
160161
161 # We count the number of characters written to the socket
162 my $wrote_len = Net::SSLeay::write( $self->{'ssl'}, substr( $buf, $offset, $len ) );
162 # don't trigger substr's magic as it is SLOOOOOOOOW!
163 # see http://www.perlmonks.org/?node_id=732873
164 my $wrote_len = Net::SSLeay::write( $self->{'ssl'}, scalar substr( $$buf, $offset, $len ) );
163165
164166 # Did we get an error or number of bytes written?
165167 # Net::SSLeay::write() returns the number of bytes written, or 0 on unsuccessful