PageRenderTime 108ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/rbczmq/rbczmq_ext.h

http://github.com/methodmissing/rbczmq
C Header | 104 lines | 89 code | 14 blank | 1 comment | 13 complexity | bf288bb1717d7ef32234aaead5d67be5 MD5 | raw file
  1. #ifndef RBCZMQ_EXT_H
  2. #define RBCZMQ_EXT_H
  3. #include <czmq.h>
  4. #include "ruby.h"
  5. /* Compiler specific */
  6. #if defined(__GNUC__) && (__GNUC__ >= 3)
  7. #define ZMQ_UNUSED __attribute__ ((unused))
  8. #define ZMQ_NOINLINE __attribute__ ((noinline))
  9. #else
  10. #define ZMQ_UNUSED
  11. #define ZMQ_NOINLINE
  12. #endif
  13. #include "rbczmq_prelude.h"
  14. #include <ruby/encoding.h>
  15. #include <ruby/io.h>
  16. extern rb_encoding *binary_encoding;
  17. #define ZmqEncode(str) rb_enc_associate(str, binary_encoding)
  18. #define ZmqRaiseSysError() { \
  19. printf("Sys error location: %s:%d\n", __FILE__,__LINE__); \
  20. rb_sys_fail(zmq_strerror(zmq_errno())); \
  21. }
  22. #define ZmqAssertSysError() if (zmq_errno() != 0 && zmq_errno() != EAGAIN) ZmqRaiseSysError();
  23. #define ZmqAssert(rc) \
  24. if (rc == -1) { \
  25. if (rc == ENOMEM) rb_memerror(); \
  26. switch (zmq_errno()) { \
  27. case EMTHREAD: \
  28. rb_raise(rb_eZmqError, "There are no I/O thread available to complete this operation. Please initialize the ZMQ context with at least one I/O thread eg. ZMQ::Context.new(1)"); \
  29. break; \
  30. default : \
  31. ZmqAssertSysError(); \
  32. break; \
  33. } \
  34. return Qfalse; \
  35. }
  36. #define ZmqAssertObjOnAlloc(obj, wrapper) \
  37. if (obj == NULL) { \
  38. xfree(wrapper); \
  39. ZmqAssertSysError(); \
  40. rb_memerror(); \
  41. }
  42. #define ZmqAssertType(obj, type, desc) \
  43. if (!rb_obj_is_kind_of(obj,type)) \
  44. rb_raise(rb_eTypeError, "wrong argument type %s (expected %s): %s", rb_obj_classname(obj), desc, RSTRING_PTR(rb_obj_as_string(obj)));
  45. extern VALUE rb_mZmq;
  46. extern VALUE rb_eZmqError;
  47. extern VALUE rb_cZmqContext;
  48. extern VALUE rb_cZmqSocket;
  49. extern VALUE rb_cZmqPubSocket;
  50. extern VALUE rb_cZmqSubSocket;
  51. extern VALUE rb_cZmqPushSocket;
  52. extern VALUE rb_cZmqPullSocket;
  53. extern VALUE rb_cZmqRouterSocket;
  54. extern VALUE rb_cZmqDealerSocket;
  55. extern VALUE rb_cZmqRepSocket;
  56. extern VALUE rb_cZmqReqSocket;
  57. extern VALUE rb_cZmqPairSocket;
  58. extern VALUE rb_cZmqXPubSocket;
  59. extern VALUE rb_cZmqXSubSocket;
  60. extern VALUE rb_cZmqStreamSocket;
  61. extern VALUE rb_cZmqFrame;
  62. extern VALUE rb_cZmqMessage;
  63. extern VALUE rb_cZmqLoop;
  64. extern VALUE rb_cZmqTimer;
  65. extern VALUE rb_cZmqPoller;
  66. extern VALUE rb_cZmqPollitem;
  67. extern VALUE rb_cZmqBeacon;
  68. extern VALUE intern_call;
  69. extern VALUE intern_readable;
  70. extern VALUE intern_writable;
  71. extern VALUE intern_error;
  72. #include "context.h"
  73. #include "socket.h"
  74. #include "frame.h"
  75. #include "message.h"
  76. #include "loop.h"
  77. #include "timer.h"
  78. #include "poller.h"
  79. #include "pollitem.h"
  80. #include "beacon.h"
  81. static inline char *rb_czmq_formatted_current_time()
  82. {
  83. time_t curtime = time (NULL);
  84. struct tm *loctime = localtime(&curtime);
  85. char *formatted;
  86. formatted = (char*)xmalloc(20);
  87. strftime(formatted, 20, "%y-%m-%d %H:%M:%S ", loctime);
  88. return formatted;
  89. }
  90. #endif