Hi ruby extension geeks, and thanks in advance for your help.
The short version of the issue that I am struggling with is that I have
a native library I created a ruby extension for. The extension works
on linux, but on windows it does not.
I have copies of the library I am extending for both windows and linux
from our vendor (Spirent). I am using gcc on linux and MSVC.NET on
windows. Everything compiles and links without complaining.
On both windows and linux I am able to successfully execute the method
"ETGetLibVersion" which gives me back the library version. I run into
trouble on windows when I try to call “ETSocketLink”. On linux this
call connects and returns as I would expect, however on windows it
connects and blocks. For example when I do a printf before and after
this call I only get output from the first printf and I have to kill
the process to get my cursor back.
Is this a problem with the way I am compiling on windows? A problem
with Spirent’s library? Or some other issue that a non-c programmer
like myself would be totally ignorant of.
Here is the relevant c and ruby code:
Ruby:
require "./smartlib.so"
include SmartLib
p eTGetLibVersion
p eTSocketLink(“192.168.1.244”, 16385)
C:
#include “ruby.h”
#include “et1000.h”
static VALUE smartlib_ETSocketLink(VALUE self, VALUE ip, VALUE port) {
int c_result;
printf(“before”);
c_result = ETSocketLink(STR2CSTR(ip), NUM2INT(port)); printf(“after”);
return Qnil;
}
static VALUE smartlib_ETGetLibVersion() {
char pszDescription[50];
char pszVersion[20];
int c_result = ETGetLibVersion(pszDescription, pszVersion);
VALUE result = rb_ary_new();
rb_ary_push(result, INT2NUM(c_result));
rb_ary_push(result, rb_str_new2(pszDescription));
rb_ary_push(result, rb_str_new2(pszVersion));
return result;
}
VALUE cSmartLib;
void Init_smartlib(){
cSmartLib=rb_define_module(“SmartLib”);
rb_define_method(cSmartLib, “eTSocketLink”, smartlib_ETSocketLink,
2); rb_define_method(cSmartLib, “eTGetLibVersion”,
smartlib_ETGetLibVersion, 0);
}