I recently resurrected my code to try to get it working again. So far
I have had no success.
Basically what I have got is a VC++ compiled .exe that works and a ruby
extension that does not. They both try to make the same library calls.
Here is the code.
Test.exe (standalone exe that works correctly):
====================================================================
#include <stdio.h>
#include "et1000.h"
int main() {
char version[9];
printf("NSUnLink Result: %d\n\n", NSUnLink());
printf("before\n");
printf("NSSocketLink Result: %d\n", NSSocketLink("192.168.1.244",
16385, 0));
printf("after\n\n");
printf("ETGetHardwareVersion Result: %d\n",
ETGetHardwareVersion(version));
printf("%s\n\n", version);
printf("NSUnLink Result: %d\n", NSUnLink());
return 0;
}
====================================================================
Which Produces:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NSUnLink Result: -2
before
NSSocketLink Result: 1
after
ETGetHardwareVersion Result: 0
SMB-6000
NSUnLink Result: 0
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
smartlib_wrap.c (c extension source):
====================================================================
#include "ruby.h"
#include "et1000.h"
#include <stdio.h>
static VALUE
_wrap_NSSocketLink(int argc, VALUE *argv, VALUE self) {
char *arg1 ;
int arg2 ;
int arg3 ;
int result;
VALUE vresult = Qnil;
if ((argc < 3) || (argc > 3))
rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc);
arg1 = StringValuePtr(argv[0]);
arg2 = NUM2INT(argv[1]);
arg3 = NUM2INT(argv[2]);
printf("before\n");
result = (int)NSSocketLink(arg1,arg2,arg3);
printf("after\n");
vresult = INT2NUM(result);
return vresult;
}
static VALUE
_wrap_NSUnLink(int argc, VALUE *argv, VALUE self) {
int result;
VALUE vresult = Qnil;
if ((argc < 0) || (argc > 0))
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc);
result = (int)NSUnLink();
vresult = INT2NUM(result);
return vresult;
}
static VALUE
_wrap_ETGetHardwareVersion(int argc, VALUE *argv, VALUE self) {
char *arg1 ;
int result;
VALUE vresult = Qnil;
if ((argc < 1) || (argc > 1))
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc);
arg1 = StringValuePtr(argv[0]);
result = (int)ETGetHardwareVersion(arg1);
vresult = INT2NUM(result);
return vresult;
}
VALUE mSmartlib;
void Init_smartlib(void) {
mSmartlib = rb_define_module("Smartlib");
rb_define_module_function(mSmartlib, "NSSocketLink",
_wrap_NSSocketLink, -1);
rb_define_module_function(mSmartlib, "NSUnLink", _wrap_NSUnLink, -1);
rb_define_module_function(mSmartlib, "ETGetHardwareVersion",
_wrap_ETGetHardwareVersion, -1);
}
====================================================================
test.rb (ruby file that uses c extension):
====================================================================
require 'smartlib'
include Smartlib
p NSUnLink()
p NSSocketLink("192.168.1.244", 16385, 0)
version = ' '
p ETGetHardwareVersion(version)
p version
p NSUnLink()
====================================================================
Which produces the following and hangs during the call to NSSocketLink
(notice it never prints out "after").
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-2
before
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Any ideas? I am particuarly puzzled by the fact that the standalone C
version works without a hitch, but the ruby extension version of my
code hangs.
Thanks, Michael
On Jan 14, 2004, at 3:14 PM, Michael Hale wrote:
> Unfortunately I don't have the source for the windows version of the
> library I am using, so I can't say what the code looks like.
>
> I did create a simple C program that I compiled into a command line
> .exe in MSVC, which works fine. Here is the pseudo code:
> connect
> get_hardware_version
> disconnect
>
> However, I still run into problems when trying to use ruby to
> interface to my library on windows.
> I am beginning to think that this could be a bug in ruby.
>
> On Dec 5, 2003, at 1:01 AM, Jon A. Lambert wrote:
>
>> Do you call ioctlsocket() to set the socket to non-blocking?
>
>
>
>
"OS X: because it was easier to make UNIX user-friendly than to fix
Windows"