|
|
|
@ -51,7 +51,7 @@ static void jdl_init_constants()
|
|
|
|
|
static void jdl_init_methods()
|
|
|
|
|
{
|
|
|
|
|
rb_define_singleton_method(mNative, "print", jdl_native_print, 2);
|
|
|
|
|
rb_define_singleton_method(mNative, "send", jdl_native_send, -1); // -1 to pass as C array
|
|
|
|
|
rb_define_singleton_method(mNative, "send", jdl_native_send, -1); /* -1 to pass as C array */
|
|
|
|
|
rb_define_singleton_method(mNative, "perror", jdl_native_perror, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -72,16 +72,20 @@ static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
|
|
|
|
|
|
|
|
|
|
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
|
|
|
|
|
{
|
|
|
|
|
//const char * fmt = "%s";
|
|
|
|
|
struct iovec *msgs;
|
|
|
|
|
size_t i;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
/* first check everything is a string / convertable to string */
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
StringValue(argv[i]); /* you may get a ruby exception here */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* allocate memory after all checks to avoid possible memory leak */
|
|
|
|
|
msgs = calloc(argc, sizeof(struct iovec));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
VALUE v = argv[i];
|
|
|
|
|
StringValue(v);
|
|
|
|
|
msgs[i].iov_base = RSTRING_PTR(v);
|
|
|
|
|
msgs[i].iov_len = RSTRING_LEN(v);
|
|
|
|
|
}
|
|
|
|
@ -119,7 +123,7 @@ static char * jdl_alloc_safe_string(VALUE v_string)
|
|
|
|
|
*ptr;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
/* convert tos sring */
|
|
|
|
|
/* convert to string */
|
|
|
|
|
StringValue(v_string);
|
|
|
|
|
|
|
|
|
|
str = RSTRING_PTR(v_string);
|
|
|
|
|