Subject: | sub _connect_sock fails silently when Cache::Memcached runs in Windows 7 |
Greetings,
I started doing some tests with Memcached with CentOS 6.4 running in a Virtual Box VM, which is hosted by a Windows 7 OS.
After running the simple test.pl file attached, I never was able to set/get the value from Memcached in the Virtual Box VM (running with IP 192.168.56.101). I double checked connection issues, and found not, since I can even use telnet to connect to the VM Memcached and use stats() command over it.
After doing some debug, I found that the sub _connect_sock was not testing for exceptions correctly, since the code fails silently in my box. I started adding some additional tests and looks like setting the socket as blocking is causing the connection with the VM to fail, but the way this condition is tested, not exception or warning is printed to STDERR.
I really don't know why the blocking set is causing such exception, but with a additional check over $^O solves the issue, but this looks like a hack since I don't know why this is not working in Windows (if it will going to work anyway).
I also modified the check process in line 234 to double check $ret and if it is false, call die to cause an exception. In other cases, a simple warning.
Here is the result if the line 215 is commented, and the 216 uncommented (please note that the string from die is localized to Brazilian Portuguese):
c:\Temp\memcached>perl -I c:\temp\memcached\Cache-Memcached-1.30\lib test.pl
connect defined errno = 10035 at c:\temp\memcached\Cache-Memcached-1.30\lib/Cache/Memcached.pm line 238.
connect() caused an fatal exception: Uma operaçăo de soquete sem bloqueio năo pôde ser concluída imediatamente. at c:\temp\memcached\Cache-Memcached-1.30\lib/Cache/Memcached.pm line 239.
This is the result if the line is uncommented and 216 commented:
c:\Temp\memcached>perl -I c:\temp\memcached\Cache-Memcached-1.30\lib test.pl
connect defined errno = 25 at c:\temp\memcached\Cache-Memcached-1.30\lib/Cache/Memcached.pm line 243.
val value1
I attached both files for your review.
From inside the CentOS VM I don't have any trouble running Cache::Memcached.
This is my environment configuration (Windows):
c:\Temp\memcached>ver
Microsoft Windows [versão 6.1.7601]
c:\Temp\memcached>perl -V
Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname='Win32 strawberry-perl 5.16.3.1 #1 Tue Mar 12 13:55:20 2013 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.6.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
libpth=C:\strawberry\c\lib C:\strawberry\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomct
l32
libc=, so=dll, useshrplib=true, libperl=libperl516.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
Characteristics of this binary (from libperl):
Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY
PERLIO_LAYERS PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB_ALLOC
USE_ITHREADS USE_LARGE_FILES USE_LOCALE
USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
Built under MSWin32
Compiled at Mar 12 2013 14:01:07
%ENV:
PERL5LIB="C:\Temp\perl\Siebel-Srvrmgr\lib;C:\Temp\perl\Siebel-Srvrmgr\t;C:\Temp\perl\Siebel-Srvrmgr\examples\Siebel-Srvrmgr-Nagios\lib"
@INC:
C:\Temp\perl\Siebel-Srvrmgr\lib
C:\Temp\perl\Siebel-Srvrmgr\t
C:\Temp\perl\Siebel-Srvrmgr\examples\Siebel-Srvrmgr-Nagios\lib
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.
Regards,
Alceu
Subject: | Memcached.pm |
Message body is not shown because it is too large.
Subject: | test.pl |
use warnings;
use strict;
use Cache::Memcached;
my $mem = Cache::Memcached->new(
{
'servers' => ['192.168.56.101:11211'],
'compress_threshold' => 10_000,
'debug' => 0
}
);
if ( $mem->set( 'key1', 'value1' ) ) {
my $val = $mem->get('key1');
print "val $val\n";
$mem->delete('key1');
}
else {
print "unable to set 'key1'\n";
}