1
1

nanomsg.d 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Boost Software License - Version 1.0 - August 17th, 2003
  3. Permission is hereby granted, free of charge, to any person or organization
  4. obtaining a copy of the software and accompanying documentation covered by
  5. this license ( the "Software" ) to use, reproduce, display, distribute,
  6. execute, and transmit the Software, and to prepare derivative works of the
  7. Software, and to permit third-parties to whom the Software is furnished to
  8. do so, all subject to the following:
  9. The copyright notices in the Software and this entire statement, including
  10. the above license grant, this restriction and the following disclaimer,
  11. must be included in all copies of the Software, in whole or in part, and
  12. all derivative works of the Software, unless such copies or derivative
  13. works are solely in the form of machine-executable object code generated by
  14. a source language processor.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  18. SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  19. FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  20. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE.
  22. */
  23. module derelict.nanomsg.nanomsg;
  24. public {
  25. import derelict.nanomsg.types;
  26. import derelict.nanomsg.functions;
  27. }
  28. private {
  29. import derelict.util.loader;
  30. import derelict.util.system;
  31. static if( Derelict_OS_Windows )
  32. enum libNames = "nanomsg.dll";
  33. else
  34. static assert( 0, "Need to implement Nanomsg2 libNames for this operating system." );
  35. }
  36. /*
  37. This function is not part of the public interface, but Nanomsg expects it to be called before any subsystems have been intiailized.
  38. Normally, this happens via linking with libNanomsgmain, but since that doesn't happen when using Derelict, then the loader must
  39. load this function and call it before the load method returns. Otherwise, bad things can happen.
  40. */
  41. private extern( C ) nothrow alias da_Nanomsg_SetMainReady = void function();
  42. class DerelictNanomsgLoader : SharedLibLoader {
  43. public this() {
  44. super( libNames );
  45. }
  46. protected override void loadSymbols() {
  47. bindFunc(cast(void**)&nanomsgErrno, "nn_errno");
  48. bindFunc(cast(void**)&nanomsgStrerror, "nn_strerror");
  49. bindFunc(cast(void**)&nanomsgSymbol, "nn_symbol");
  50. bindFunc(cast(void**)&nanomsgSymbolInfo, "nn_symbol_info");
  51. bindFunc(cast(void**)&nanomsgTerm, "nn_term");
  52. bindFunc(cast(void**)&nanomsgAllocmsg, "nn_allocmsg");
  53. bindFunc(cast(void**)&nanomsgFreemsg, "nn_freemsg");
  54. bindFunc(cast(void**)&nanomsgSocket, "nn_socket");
  55. bindFunc(cast(void**)&nanomsgClose, "nn_close");
  56. bindFunc(cast(void**)&nanomsgSetsockopt, "nn_setsockopt");
  57. bindFunc(cast(void**)&nanomsgGetsockopt, "nn_getsockopt");
  58. bindFunc(cast(void**)&nanomsgBind, "nn_bind");
  59. bindFunc(cast(void**)&nanomsgConnect, "nn_connect");
  60. bindFunc(cast(void**)&nanomsgShutdown, "nn_shutown");
  61. bindFunc(cast(void**)&nanomsgSend, "nn_send");
  62. bindFunc(cast(void**)&nanomsgRecv, "nn_recv");
  63. bindFunc(cast(void**)&nanomsgSendmsg, "nn_sendmsg");
  64. bindFunc(cast(void**)&nanomsgRecvMsg, "nn_recvmsg");
  65. bindFunc(cast(void**)&nanomsgPoll, "nn_poll");
  66. bindFunc(cast(void**)&nanomsgDevice, "nn_device");
  67. }
  68. }
  69. __gshared DerelictNanomsgLoader DerelictNanomsg;
  70. shared static this() {
  71. DerelictNanomsg = new DerelictNanomsgLoader();
  72. }
  73. shared static ~this()
  74. {
  75. DerelictNanomsg.unload();
  76. }