芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/avenida/views/zeromq-0.0.2.tar
extension/zeromq.c 0000644 00000021357 14716407612 0010261 0 ustar 00 //----------------------------------------------------------------------------- #include "zeromq.h" #include "socket.h" //----------------------------------------------------------------------------- static VALUE module_version( VALUE self ); static VALUE module_select( int argument_count, VALUE* arguments, VALUE self ); //----------------------------------------------------------------------------- VALUE module_declare() //-------------------- { VALUE zmq_module = rb_define_module( "ZeroMQ" ); rb_define_singleton_method( zmq_module, "version", module_version, 0 ); rb_define_singleton_method( zmq_module, "select", module_select, -1 ); rb_define_const (zmq_module, "SNDHWM", INT2NUM (ZMQ_SNDHWM)); rb_define_const (zmq_module, "RCVHWM", INT2NUM (ZMQ_RCVHWM)); rb_define_const (zmq_module, "AFFINITY", INT2NUM (ZMQ_AFFINITY)); rb_define_const (zmq_module, "IDENTITY", INT2NUM (ZMQ_IDENTITY)); rb_define_const (zmq_module, "SUBSCRIBE", INT2NUM (ZMQ_SUBSCRIBE)); rb_define_const (zmq_module, "UNSUBSCRIBE", INT2NUM (ZMQ_UNSUBSCRIBE)); rb_define_const (zmq_module, "RATE", INT2NUM (ZMQ_RATE)); rb_define_const (zmq_module, "RECOVERY_IVL", INT2NUM (ZMQ_RECOVERY_IVL)); rb_define_const (zmq_module, "SNDBUF", INT2NUM (ZMQ_SNDBUF)); rb_define_const (zmq_module, "RCVBUF", INT2NUM (ZMQ_RCVBUF)); rb_define_const (zmq_module, "SNDMORE", INT2NUM (ZMQ_SNDMORE)); rb_define_const (zmq_module, "RCVMORE", INT2NUM (ZMQ_RCVMORE)); rb_define_const (zmq_module, "FD", INT2NUM (ZMQ_FD)); rb_define_const (zmq_module, "EVENTS", INT2NUM (ZMQ_EVENTS)); rb_define_const (zmq_module, "TYPE", INT2NUM (ZMQ_TYPE)); rb_define_const (zmq_module, "LINGER", INT2NUM (ZMQ_LINGER)); rb_define_const (zmq_module, "RECONNECT_IVL", INT2NUM (ZMQ_RECONNECT_IVL)); rb_define_const (zmq_module, "BACKLOG", INT2NUM (ZMQ_BACKLOG)); rb_define_const (zmq_module, "RECONNECT_IVL_MAX", INT2NUM (ZMQ_RECONNECT_IVL_MAX)); rb_define_const (zmq_module, "RECOVERY_IVL_MSEC", INT2NUM (ZMQ_RECOVERY_IVL)); rb_define_const (zmq_module, "SNDTIMEO", INT2NUM (ZMQ_SNDTIMEO)); rb_define_const (zmq_module, "RCVTIMEO", INT2NUM (ZMQ_RCVTIMEO)); rb_define_const (zmq_module, "NOBLOCK", INT2NUM (ZMQ_NOBLOCK)); rb_define_const (zmq_module, "PAIR", INT2NUM (ZMQ_PAIR)); rb_define_const (zmq_module, "SUB", INT2NUM (ZMQ_SUB)); rb_define_const (zmq_module, "PUB", INT2NUM (ZMQ_PUB)); rb_define_const (zmq_module, "REQ", INT2NUM (ZMQ_REQ)); rb_define_const (zmq_module, "REP", INT2NUM (ZMQ_REP)); return zmq_module; } static VALUE module_version( VALUE self_ ) { int major, minor, patch; zmq_version(&major, &minor, &patch); return rb_ary_new3 (3, INT2NUM (major), INT2NUM (minor), INT2NUM (patch)); } struct poll_state { int event; int nitems; zmq_pollitem_t *items; VALUE io_objects; }; typedef VALUE(*iterfunc)(ANYARGS); static VALUE poll_add_item(VALUE io_, void *ps_) { struct poll_state *state = (struct poll_state *)ps_; long i; for (i = 0; i < RARRAY_LEN (state->io_objects); i++) { if (RARRAY_PTR (state->io_objects)[i] == io_) { #ifdef HAVE_RUBY_IO_H state->items[i].events |= state->event; return Qnil; #else if (CLASS_OF (io_) == socket_class) { state->items[i].events |= state->event; return Qnil; } OpenFile *fptr; GetOpenFile (io_, fptr); if (state->event == ZMQ_POLLOUT && GetWriteFile (fptr) != NULL && fileno (GetWriteFile (fptr)) != state->items[i].fd) { break; } else { state->items[i].events |= state->event; return Qnil; } #endif } } /* Not found in array. Add a new poll item. */ rb_ary_push (state->io_objects, io_); zmq_pollitem_t *item = &state->items[state->nitems]; state->nitems++; item->events = state->event; if (CLASS_OF (io_) == socket_class) { struct zeromq_socket* socket; Data_Get_Struct( io_, struct zeromq_socket, socket ); item->socket = socket->socket; item->fd = -1; } else { item->socket = NULL; #ifdef HAVE_RUBY_IO_H rb_io_t *fptr; GetOpenFile (io_, fptr); item->fd = fileno (rb_io_stdio_file (fptr)); #else OpenFile *fptr; GetOpenFile (io_, fptr); if (state->event == ZMQ_POLLIN && GetReadFile (fptr) != NULL) { item->fd = fileno (GetReadFile (fptr)); } else if (state->event == ZMQ_POLLOUT && GetWriteFile (fptr) != NULL) { item->fd = fileno (GetWriteFile (fptr)); } else if (state->event == ZMQ_POLLERR) { if (GetReadFile(fptr) != NULL) item->fd = fileno (GetReadFile (fptr)); else item->fd = fileno (GetWriteFile (fptr)); } #endif } return Qnil; } #ifdef HAVE_RUBY_INTERN_H struct zmq_poll_args { zmq_pollitem_t *items; int nitems; long timeout_usec; int rc; }; static VALUE zmq_poll_blocking (void* args_) { struct zmq_poll_args *poll_args = (struct zmq_poll_args *)args_; poll_args->rc = zmq_poll (poll_args->items, poll_args->nitems, poll_args->timeout_usec); return Qnil; } #endif struct select_arg { VALUE readset; VALUE writeset; VALUE errset; long timeout_usec; zmq_pollitem_t *items; }; static VALUE internal_select(VALUE argval) { struct select_arg *arg = (struct select_arg *)argval; int rc, nitems, i; zmq_pollitem_t *item; struct poll_state ps; ps.nitems = 0; ps.items = arg->items; ps.io_objects = rb_ary_new (); if (!NIL_P (arg->readset)) { ps.event = ZMQ_POLLIN; rb_iterate(rb_each, arg->readset, (iterfunc)poll_add_item, (VALUE)&ps); } if (!NIL_P (arg->writeset)) { ps.event = ZMQ_POLLOUT; rb_iterate(rb_each, arg->writeset, (iterfunc)poll_add_item, (VALUE)&ps); } if (!NIL_P (arg->errset)) { ps.event = ZMQ_POLLERR; rb_iterate(rb_each, arg->errset, (iterfunc)poll_add_item, (VALUE)&ps); } /* Reset nitems to the actual number of zmq_pollitem_t records we're sending. */ nitems = ps.nitems; #ifdef HAVE_RUBY_INTERN_H if (arg->timeout_usec != 0) { struct zmq_poll_args poll_args; poll_args.items = ps.items; poll_args.nitems = ps.nitems; poll_args.timeout_usec = arg->timeout_usec; rb_thread_blocking_region (zmq_poll_blocking, (void*)&poll_args, NULL, NULL); rc = poll_args.rc; } else #endif rc = zmq_poll (ps.items, ps.nitems, arg->timeout_usec); if (rc == -1) { rb_raise(exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } else if (rc == 0) return Qnil; VALUE read_active = rb_ary_new (); VALUE write_active = rb_ary_new (); VALUE err_active = rb_ary_new (); for (i = 0, item = &ps.items[0]; i < nitems; i++, item++) { if (item->revents != 0) { VALUE io = RARRAY_PTR (ps.io_objects)[i]; if (item->revents & ZMQ_POLLIN) rb_ary_push (read_active, io); if (item->revents & ZMQ_POLLOUT) rb_ary_push (write_active, io); if (item->revents & ZMQ_POLLERR) rb_ary_push (err_active, io); } } return rb_ary_new3 (3, read_active, write_active, err_active); } static VALUE module_select_internal(VALUE readset, VALUE writeset, VALUE errset, long timeout_usec) { size_t nitems; struct select_arg arg; /* Conservative estimate for nitems before we traverse the lists. */ nitems = (NIL_P (readset) ? 0 : RARRAY_LEN (readset)) + (NIL_P (writeset) ? 0 : RARRAY_LEN (writeset)) + (NIL_P (errset) ? 0 : RARRAY_LEN (errset)); arg.items = ALLOC_N(zmq_pollitem_t, nitems); arg.readset = readset; arg.writeset = writeset; arg.errset = errset; arg.timeout_usec = timeout_usec; return rb_ensure(internal_select, (VALUE)&arg, (VALUE (*)())xfree, (VALUE)arg.items); } static VALUE module_select (int argc_, VALUE* argv_, VALUE self_) { VALUE readset, writeset, errset, timeout; rb_scan_args (argc_, argv_, "13", &readset, &writeset, &errset, &timeout); long timeout_usec; if (!NIL_P (readset)) Check_Type (readset, T_ARRAY); if (!NIL_P (writeset)) Check_Type (writeset, T_ARRAY); if (!NIL_P (errset)) Check_Type (errset, T_ARRAY); if (NIL_P (timeout)) timeout_usec = -1; else timeout_usec = (long)(NUM2DBL (timeout) * 1000000); return module_select_internal(readset, writeset, errset, timeout_usec); } extension/socket.c 0000644 00000041104 14716407612 0010224 0 ustar 00 //----------------------------------------------------------------------------- #include "socket.h" #include "context.h" //----------------------------------------------------------------------------- #define Check_Socket(__socket) \ do {\ if ((__socket->socket) == NULL)\ rb_raise (rb_eIOError, "closed socket");\ } while(0) //----------------------------------------------------------------------------- // ZeroMQ::Socket method declarations static VALUE socket_allocate( VALUE socket_class ); void socket_free( void* instance ); static VALUE socket_initialize( int count, VALUE* arguments, VALUE self ); static VALUE socket_close( VALUE self ); static VALUE socket_getsockopt( VALUE self, VALUE option ); static VALUE socket_setsockopt( VALUE self, VALUE option, VALUE value ); static VALUE socket_bind( VALUE self, VALUE addr_ ); static VALUE socket_connect( VALUE self, VALUE addr_ ); static VALUE socket_recv( int argc_, VALUE* argv_, VALUE self_ ); static VALUE socket_send( int argc_, VALUE* argv_, VALUE self_ ); //----------------------------------------------------------------------------- // zeromq socket helper functions struct zeromq_socket_io_request { void* socket; zmq_msg_t* message; int flags; int result; }; struct zeromq_socket* zeromq_socket_create() //------------------------------------------ { struct zeromq_socket* socket; socket = ALLOC( struct zeromq_socket ); socket->context = NULL; socket->socket = NULL; return socket; } void zeromq_socket_destroy( struct zeromq_socket* zeromq_socket ) //--------------------------------------------------------------- { if ( zeromq_socket->socket != NULL ) { int rc = zmq_close( zeromq_socket->socket ); assert( rc == 0 ); } if ( zeromq_socket->context != NULL ) { zeromq_context_release( zeromq_socket->context ); } xfree( zeromq_socket ); } static VALUE zeromq_socket_send_blocking_region( void* argument ) //--------------------------------------------------------------- { struct zeromq_socket_io_request* io_request = ( struct zeromq_socket_io_request* )argument; io_request->result = zmq_sendmsg( io_request->socket, io_request->message, io_request->flags ); return Qnil; } static VALUE zeromq_socket_receive_blocking_region( void* argument ) //------------------------------------------------------------------ { struct zeromq_socket_io_request* io_request = ( struct zeromq_socket_io_request* )argument; io_request->result = zmq_recvmsg( io_request->socket, io_request->message, io_request->flags ); return Qnil; } int zeromq_apply_socket_option( VALUE option, VALUE value, VALUE socket ) //----------------------------------------------------------------------- { socket_setsockopt( socket, option, value ); return ST_CONTINUE; } /* * Document-class: ZeroMQ::Socket * * The Socket class ... */ /* call-seq: new() * * The new method does some stuff. */ //---------------------------------------------------------------------------- VALUE socket_declare( VALUE zeromq_module ) //----------------------------------------- { VALUE klass = Qnil; klass = rb_define_class_under( zeromq_module, "Socket", rb_cObject ); rb_define_alloc_func( klass, socket_allocate ); rb_define_method( klass, "initialize", socket_initialize, -1 ); rb_define_method( klass, "getsockopt", socket_getsockopt, 1 ); rb_define_method( klass, "setsockopt", socket_setsockopt, 2 ); rb_define_method( klass, "bind", socket_bind, 1 ); rb_define_method( klass, "connect", socket_connect, 1 ); rb_define_method( klass, "send", socket_send, -1 ); rb_define_method( klass, "recv", socket_recv, -1 ); rb_define_method( klass, "close", socket_close, 0 ); rb_define_alias( klass, "receive", "recv" ); return klass; } //----------------------------------------------------------------------------- // ZeroMQ::Socket method implmentation static VALUE socket_allocate( VALUE socket_class ) //------------------------------------------------ { return rb_data_object_alloc( socket_class, zeromq_socket_create(), 0, socket_free ); } void socket_free( void* instance ) //-------------------------------- { zeromq_socket_destroy( ( struct zeromq_socket* )instance ); } static VALUE socket_initialize( int arg_count, VALUE* arguments, VALUE self ) //--------------------------------------------------------------------------- { struct zeromq_socket* socket = NULL; Data_Get_Struct( self, void, socket ); VALUE context = Qnil; VALUE socket_type = Qnil; VALUE socket_options = Qnil; rb_scan_args( arg_count, arguments, "12", &context, &socket_type, &socket_options ); if ( CLASS_OF( context ) != context_class ) { socket_options = socket_type; socket_type = context; context = Qnil; } if ( context == Qnil ) { context = context_default( context_class ); } if ( socket_type == Qnil ) { rb_raise( exception_class, "The socket type is required." ); return Qnil; } struct zeromq_context* context_struct = NULL; Data_Get_Struct( context, void, context_struct ); socket->socket = zmq_socket( context_struct->context, NUM2INT( socket_type ) ); if ( !socket->socket ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } socket->context = context_struct; zeromq_context_retain( socket->context ); if ( CLASS_OF( socket_options ) == rb_cHash ) { rb_hash_foreach( socket_options, zeromq_apply_socket_option, self ); } return self; } static VALUE socket_close( VALUE self_ ) //-------------------------------------- { struct zeromq_socket * s; Data_Get_Struct (self_, struct zeromq_socket, s); if (s->socket != NULL) { int rc = zmq_close(s->socket); if (rc != 0) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } s->socket = NULL; /* Decrement the refcounter for the context (and possibly free it). */ zeromq_context_release( s->context ); s->context = NULL; } return Qnil; } static VALUE socket_getsockopt( VALUE self_, VALUE option_ ) { int rc = 0; VALUE retval; struct zeromq_socket * s; Data_Get_Struct (self_, struct zeromq_socket, s); Check_Socket (s); switch ( NUM2INT( option_ ) ) { case ZMQ_FD: { #ifdef _WIN32 SOCKET optval; #else int optval; #endif size_t optvalsize = sizeof( optval ); rc = zmq_getsockopt( s->socket, NUM2INT( option_ ), ( void* )&optval, &optvalsize ); if ( rc != 0 ) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } if ( NUM2INT( option_ ) == ZMQ_RCVMORE ) retval = optval ? Qtrue : Qfalse; else retval = INT2NUM (optval); } break; case ZMQ_EVENTS: { uint32_t optval; size_t optvalsize = sizeof(optval); rc = zmq_getsockopt( s->socket, NUM2INT( option_ ), ( void* )&optval, &optvalsize ); if ( rc != 0 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } if ( NUM2INT( option_ ) == ZMQ_RCVMORE ) retval = optval ? Qtrue : Qfalse; else retval = INT2NUM( optval ); } break; case ZMQ_TYPE: case ZMQ_LINGER: case ZMQ_RECONNECT_IVL: case ZMQ_BACKLOG: case ZMQ_RECONNECT_IVL_MAX: case ZMQ_SNDTIMEO: case ZMQ_RCVTIMEO: case ZMQ_RCVHWM: case ZMQ_SNDHWM: { int optval; size_t optvalsize = sizeof( optval ); rc = zmq_getsockopt( s->socket, NUM2INT( option_ ), ( void* )&optval, &optvalsize ); if ( rc != 0 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } if ( NUM2INT( option_ ) == ZMQ_RCVMORE ) retval = optval ? Qtrue : Qfalse; else retval = INT2NUM (optval); } break; case ZMQ_RCVMORE: case ZMQ_AFFINITY: case ZMQ_RATE: case ZMQ_RECOVERY_IVL: case ZMQ_SNDBUF: case ZMQ_RCVBUF: { int64_t optval; size_t optvalsize = sizeof(optval); rc = zmq_getsockopt (s->socket, NUM2INT (option_), (void *)&optval, &optvalsize); if (rc != 0) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } if (NUM2INT (option_) == ZMQ_RCVMORE) retval = optval ? Qtrue : Qfalse; else retval = INT2NUM (optval); } break; case ZMQ_IDENTITY: { char identity[255]; size_t optvalsize = sizeof (identity); rc = zmq_getsockopt (s->socket, NUM2INT (option_), (void *)identity, &optvalsize); if (rc != 0) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } if (optvalsize > sizeof (identity)) optvalsize = sizeof (identity); retval = rb_str_new (identity, optvalsize); } break; default: rb_raise (exception_class, "%s", zmq_strerror (EINVAL)); return Qnil; } return retval; } static VALUE socket_setsockopt( VALUE self_, VALUE option_, VALUE optval_ ) //------------------------------------------------------------------------- { int rc = 0; struct zeromq_socket * s; Data_Get_Struct (self_, struct zeromq_socket, s); Check_Socket (s); switch ( NUM2INT( option_ ) ) { case ZMQ_AFFINITY: case ZMQ_RATE: case ZMQ_RECOVERY_IVL: case ZMQ_SNDBUF: case ZMQ_RCVBUF: { uint64_t optval = FIX2LONG (optval_); // Forward the code to native 0MQ library. rc = zmq_setsockopt( s->socket, NUM2INT( option_ ), ( void* ) &optval, sizeof( optval ) ); } break; case ZMQ_RCVHWM: case ZMQ_SNDHWM: case ZMQ_LINGER: case ZMQ_RECONNECT_IVL: case ZMQ_BACKLOG: case ZMQ_RECONNECT_IVL_MAX: case ZMQ_SNDTIMEO: case ZMQ_RCVTIMEO: { int optval = FIX2INT (optval_); // Forward the code to native 0MQ library. rc = zmq_setsockopt( s->socket, NUM2INT( option_ ), ( void* )&optval, sizeof( optval ) ); } break; case ZMQ_IDENTITY: case ZMQ_SUBSCRIBE: case ZMQ_UNSUBSCRIBE: { // Forward the code to native 0MQ library. rc = zmq_setsockopt( s->socket, NUM2INT( option_ ), ( void* )StringValueCStr( optval_ ), RSTRING_LEN( optval_ ) ); } break; default: { rb_raise( exception_class, "%s", zmq_strerror( EINVAL ) ); return Qnil; } } if ( rc != 0 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } return self_; } static VALUE socket_bind( VALUE self_, VALUE addr_ ) //-------------------------------------------------- { struct zeromq_socket * s; Data_Get_Struct (self_, struct zeromq_socket, s); Check_Socket (s); int rc = zmq_bind (s->socket, rb_string_value_cstr (&addr_)); if (rc != 0) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } return Qnil; } static VALUE socket_connect( VALUE self_, VALUE addr_ ) //----------------------------------------------------- { struct zeromq_socket * s; Data_Get_Struct (self_, struct zeromq_socket, s); Check_Socket (s); int rc = zmq_connect (s->socket, rb_string_value_cstr (&addr_)); if (rc != 0) { rb_raise (exception_class, "%s", zmq_strerror (zmq_errno ())); return Qnil; } return Qnil; } static VALUE socket_send( int argument_count, VALUE* arguments, VALUE self ) //-------------------------------------------------------------------------- { VALUE message_bytes_value, flags_value; rb_scan_args( argument_count, arguments, "11", &message_bytes_value, &flags_value ); Check_Type( message_bytes_value, T_STRING ); int flags = NIL_P( flags_value ) ? 0 : NUM2INT( flags_value ); struct zeromq_socket* socket; Data_Get_Struct( self, struct zeromq_socket, socket ); Check_Socket( socket ); zmq_msg_t message; int message_length = ( int )RSTRING_LEN( message_bytes_value ); int result = zmq_msg_init_size( &message, message_length ); if ( result != 0 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } memcpy( zmq_msg_data( &message ), RSTRING_PTR( message_bytes_value ), message_length ); if ( !( flags & ZMQ_NOBLOCK ) ) { struct zeromq_socket_io_request io_request; io_request.socket = socket->socket; io_request.message = &message; io_request.flags = flags; rb_thread_blocking_region( zeromq_socket_send_blocking_region, ( void* )&io_request, NULL, NULL ); result = io_request.result; } else { result = zmq_sendmsg( socket->socket, &message, flags ); } if ( result == -1 && zmq_errno() == EAGAIN ) { result = zmq_msg_close( &message ); assert( result == 0 ); return Qfalse; } if ( result == -1 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); result = zmq_msg_close( &message ); assert( result == 0 ); return Qnil; } result = zmq_msg_close( &message ); assert( result == 0 ); return Qtrue; } static VALUE socket_recv( int argument_count, VALUE* arguments, VALUE self ) //-------------------------------------------------------------------------- { VALUE flags_value; rb_scan_args( argument_count, arguments, "01", &flags_value ); int flags = NIL_P( flags_value ) ? 0 : NUM2INT( flags_value ); struct zeromq_socket* socket; Data_Get_Struct( self, struct zeromq_socket, socket ); Check_Socket( socket ); zmq_msg_t message; int rc = zmq_msg_init( &message ); assert( rc == 0 ); if ( !( flags & ZMQ_NOBLOCK ) ) { struct zeromq_socket_io_request io_request; io_request.socket = socket->socket; io_request.message = &message; io_request.flags = flags; rb_thread_blocking_region( zeromq_socket_receive_blocking_region, ( void* )&io_request, NULL, NULL ); } else { rc = zmq_recvmsg( socket->socket, &message, flags ); } if ( rc == -1 && zmq_errno() == EAGAIN ) { rc = zmq_msg_close( &message ); assert( rc == 0 ); return Qnil; } if ( rc == -1 ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); rc = zmq_msg_close( &message ); assert( rc == 0 ); return Qnil; } VALUE message_bytes_value = rb_str_new( ( char* )zmq_msg_data( &message ), zmq_msg_size( &message ) ); rc = zmq_msg_close( &message ); assert( rc == 0 ); return message_bytes_value; } extension/siteconf20190111-799172-1rtawet-0.rb 0000644 00000000400 14716407612 0014042 0 ustar 00 require 'rbconfig' dest_path = "./.gem.20190111-799172-1oiqt4v" RbConfig::MAKEFILE_CONFIG['sitearchdir'] = dest_path RbConfig::CONFIG['sitearchdir'] = dest_path RbConfig::MAKEFILE_CONFIG['sitelibdir'] = dest_path RbConfig::CONFIG['sitelibdir'] = dest_path extension/mkmf.log 0000644 00000002053 14716407612 0010225 0 ustar 00 have_header: checking for zmq.h... -------------------- no "gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -o conftest.i" checked program was: /* begin */ 1: #include
/* end */ -------------------- find_header: checking for zmq.h in /opt/local/include,/usr/local/include,/usr/include... -------------------- no "gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -o conftest.i" checked program was: /* begin */ 1: #include
/* end */ "gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC -I/opt/local/include conftest.c -o conftest.i" checked program was: /* begin */ 1: #include
/* end */ "gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC -I/usr/local/include conftest.c -o conftest.i" checked program was: /* begin */ 1: #include
/* end */ "gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC -I/usr/include conftest.c -o conftest.i" checked program was: /* begin */ 1: #include
/* end */ -------------------- extension/extension.h 0000644 00000003000 14716407612 0010746 0 ustar 00 /* Copyright (c) 2007-2010 iMatix Corporation This file is part of 0MQ. 0MQ is free software; you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 0MQ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program. If not, see
. */ #include
#include
#include
#ifdef HAVE_RUBY_IO_H #include
#else #include
#endif #include
#if defined _MSC_VER #ifndef int8_t typedef __int8 int8_t; #endif #ifndef int16_t typedef __int16 int16_t; #endif #ifndef int32_t typedef __int32 int32_t; #endif #ifndef int64_t typedef __int64 int64_t; #endif #ifndef uint8_t typedef unsigned __int8 uint8_t; #endif #ifndef uint16_t typedef unsigned __int16 uint16_t; #endif #ifndef uint32_t typedef unsigned __int32 uint32_t; #endif #ifndef uint64_t typedef unsigned __int64 uint64_t; #endif #else #include
#endif //----------------------------------------------------------------------------- extern VALUE context_class; extern VALUE socket_class; extern VALUE exception_class; extension/context.c 0000644 00000007555 14716407612 0010434 0 ustar 00 //----------------------------------------------------------------------------- #include "context.h" #include "socket.h" //----------------------------------------------------------------------------- static VALUE context_allocate( VALUE klass ); static void context_free( void* instance ); static VALUE context_initialize( int argc_, VALUE* argv_, VALUE self ); static VALUE context_close( VALUE self ); //----------------------------------------------------------------------------- struct zeromq_context* zeromq_context_create() //-------------------------------------------- { struct zeromq_context* context = NULL; context = ALLOC( struct zeromq_context ); context->context = NULL; context->reference_count = 1; return context; } void zeromq_context_destroy( struct zeromq_context* context ) //----------------------------------------------------------- { assert( context ); if ( context->context != NULL ) { int rc = zmq_ctx_destroy( context->context ); assert( rc == 0 ); } xfree( context ); } void zeromq_context_retain( struct zeromq_context* context ) //---------------------------------------------------------- { assert( context ); assert( context->context ); assert( context->reference_count != 0 ); context->reference_count++; } void zeromq_context_release( struct zeromq_context* context ) //----------------------------------------------------------- { assert( context ); assert( context->context ); assert( context->reference_count != 0 ); context->reference_count--; if ( context->reference_count == 0 ) { zeromq_context_destroy( context ); } } //----------------------------------------------------------------------------- /* * Document-class: ZeroMQ::Context * * The ZeroMQ::Context class ... */ VALUE context_declare( VALUE zeromq_module ) //------------------------------------------ { VALUE klass = rb_define_class_under( zeromq_module, "Context", rb_cObject ); rb_define_singleton_method( klass, "default", context_default, 0 ); rb_define_alloc_func( klass, context_allocate ); rb_define_method( klass, "initialize", context_initialize, -1 ); rb_define_method( klass, "close", context_close, 0 ); return klass; } /* * @!method default * * The +default+ method ... */ VALUE context_default( VALUE self ) //--------------------------------- { static VALUE default_context = Qnil; if ( default_context == Qnil ) { default_context = rb_class_new_instance( 0, NULL, self ); } return default_context; } static VALUE context_allocate( VALUE class ) //------------------------------------------ { return rb_data_object_alloc( class, zeromq_context_create(), 0, context_free ); } static void context_free( void* instance ) //---------------------------------------- { zeromq_context_destroy( ( struct zeromq_context* )instance ); } static VALUE context_initialize( int arg_count, VALUE* args, VALUE self ) //------------------------------------------------------------------------ { VALUE context_options = Qnil; rb_scan_args( arg_count, args, "01", &context_options ); struct zeromq_context* context = NULL; Data_Get_Struct( self, void, context ); assert( context->context == NULL ); context->context = zmq_ctx_new(); if ( !context->context ) { rb_raise( exception_class, "%s", zmq_strerror( zmq_errno() ) ); return Qnil; } return self; } static VALUE context_close( VALUE self ) //-------------------------------------- { struct zeromq_context* context = NULL; Data_Get_Struct( self, void, context ); if ( context->context != NULL ) { zeromq_context_destroy( context ); } return Qnil; } extension/extension.c 0000644 00000000615 14716407612 0010752 0 ustar 00 #include "extension.h" #include "zeromq.h" #include "error.h" #include "context.h" #include "socket.h" VALUE module; VALUE exception_class; VALUE context_class; VALUE socket_class; void Init_zeromq() //---------------- { module = module_declare(); exception_class = error_declare( module ); context_class = context_declare( module ); socket_class = socket_declare( module ); } extension/zeromq.h 0000644 00000000060 14716407612 0010252 0 ustar 00 #include "extension.h" VALUE module_declare(); extension/socket.h 0000644 00000000773 14716407612 0010240 0 ustar 00 #include "extension.h" //----------------------------------------------------------------------------- struct zeromq_socket { void* socket; struct zeromq_context* context; }; //----------------------------------------------------------------------------- struct zeromq_socket* zeromq_socket_create(); void zeromq_socket_destroy( struct zeromq_socket* ); //----------------------------------------------------------------------------- VALUE socket_declare( VALUE zeromq_module ); extension/context.h 0000644 00000001325 14716407612 0010426 0 ustar 00 #include "extension.h" //----------------------------------------------------------------------------- struct zeromq_context { void* context; unsigned reference_count; }; //----------------------------------------------------------------------------- struct zeromq_context* zeromq_context_default(); struct zeromq_context* zeromq_context_create(); void zeromq_context_destroy( struct zeromq_context* context ); void zeromq_context_retain( struct zeromq_context* context ); void zeromq_context_release( struct zeromq_context* context ); //----------------------------------------------------------------------------- VALUE context_declare( VALUE zeromq_module ); VALUE context_default( VALUE self ); extension/extconf.rb 0000644 00000001073 14716407612 0010564 0 ustar 00 require 'mkmf' dir_config( 'zeromq' ) def header? have_header( 'zmq.h' ) || find_header( 'zmq.h', '/opt/local/include', '/usr/local/include', '/usr/include' ) end def library? have_library( 'zmq', 'zmq_init' ) || find_library( 'zmq', 'zmq_init', '/opt/local/lib', '/usr/local/lib', '/usr/lib' ) end if header? && library? puts "Cool, I found your zmq install..." create_makefile( 'zeromq' ) else raise "Couldn't find zmq library. try setting --with-zmq-dir=
to tell me where it is." end extension/error.c 0000644 00000000642 14716407612 0010067 0 ustar 00 /* * Document-class: ZeroMQ::Error * * The ZeroMQ::Error class ... */ //----------------------------------------------------------------------------- #include "error.h" //----------------------------------------------------------------------------- VALUE error_declare( VALUE zeromq_module ) { return rb_define_class_under( zeromq_module, "Error", rb_eRuntimeError ); } extension/error.h 0000644 00000000345 14716407612 0010074 0 ustar 00 //----------------------------------------------------------------------------- #include "extension.h" //----------------------------------------------------------------------------- VALUE error_declare( VALUE zeromq_module ); extension/gem_make.out 0000644 00000001563 14716407612 0011073 0 ustar 00 /usr/bin/ruby extconf.rb checking for zmq.h... no checking for zmq.h in /opt/local/include,/usr/local/include,/usr/include... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/bin/ruby --with-zeromq-dir --without-zeromq-dir --with-zeromq-include --without-zeromq-include=${zeromq-dir}/include --with-zeromq-lib --without-zeromq-lib=${zeromq-dir}/lib extconf.rb:37: Couldn't find zmq library. try setting --with-zmq-dir=
to tell me where it is. (RuntimeError) lib/zeromq/version.rb 0000644 00000000045 14716407612 0010650 0 ustar 00 module ZeroMQ VERSION = '0.0.2' end