nng 0.1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/rbnng/bus0.c DELETED
@@ -1,43 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/bus0/bus.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_bus0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_bus0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- if ((rv = nng_socket_set_ms(p_rbnngSocket->socket, NNG_OPT_RECVTIMEO, 100)) != 0) {
23
- raise_error(rv);
24
- return Qnil;
25
- }
26
-
27
- return self;
28
- }
29
-
30
- void
31
- rbnng_bus0_Init(VALUE nng_module)
32
- {
33
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
34
- VALUE rbnng_SocketBus0Class =
35
- rb_define_class_under(rbnng_SocketModule, "Bus0", rb_cObject);
36
- rb_define_alloc_func(rbnng_SocketBus0Class, socket_alloc);
37
- rb_define_method(
38
- rbnng_SocketBus0Class, "initialize", socket_bus0_initialize, 0);
39
- rb_define_method(rbnng_SocketBus0Class, "get_msg", socket_get_msg, 0);
40
- rb_define_method(rbnng_SocketBus0Class, "send_msg", socket_send_msg, 1);
41
- rb_define_method(rbnng_SocketBus0Class, "listen", socket_listen, 1);
42
- rb_define_method(rbnng_SocketBus0Class, "dial", socket_dial, 1);
43
- }
@@ -1,12 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
-
6
- #ifndef RBNNG_EXCEPTIONS_H
7
- #define RBNNG_EXCEPTIONS_H
8
-
9
- extern void
10
- raise_error(int);
11
-
12
- #endif
data/ext/rbnng/msg.c DELETED
@@ -1,61 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include <nng/protocol/reqrep0/rep.h>
7
- #include <ruby.h>
8
- #include <signal.h>
9
-
10
- VALUE rbnng_MsgClass = Qnil;
11
-
12
- void
13
- msg_free(RbnngMsg* p_rbnngMsg)
14
- {
15
- if (p_rbnngMsg->p_msg) {
16
- nng_msg_free(p_rbnngMsg->p_msg);
17
- }
18
- xfree(p_rbnngMsg);
19
- }
20
-
21
- static VALUE
22
- msg_alloc(VALUE klass)
23
- {
24
- RbnngMsg* p_rbnngMsg = ZALLOC(RbnngMsg);
25
- return rb_data_object_wrap(klass, p_rbnngMsg, 0, msg_free);
26
- }
27
-
28
- static VALUE
29
- msg_body(VALUE self)
30
- {
31
- RbnngMsg* p_rbnngMsg;
32
- Data_Get_Struct(self, RbnngMsg, p_rbnngMsg);
33
- if (p_rbnngMsg->p_msg) {
34
- return rb_str_new(nng_msg_body(p_rbnngMsg->p_msg),
35
- nng_msg_len(p_rbnngMsg->p_msg));
36
- } else {
37
- return rb_str_new_cstr("");
38
- }
39
- }
40
-
41
- static VALUE
42
- msg_header(VALUE self)
43
- {
44
- RbnngMsg* p_rbnngMsg;
45
- Data_Get_Struct(self, RbnngMsg, p_rbnngMsg);
46
- if (p_rbnngMsg->p_msg) {
47
- return rb_str_new(nng_msg_header(p_rbnngMsg->p_msg),
48
- nng_msg_header_len(p_rbnngMsg->p_msg));
49
- } else {
50
- return rb_str_new_cstr("");
51
- }
52
- }
53
-
54
- void
55
- rbnng_msg_Init(VALUE nng_module)
56
- {
57
- rbnng_MsgClass = rb_define_class_under(nng_module, "Msg", rb_cObject);
58
- rb_define_alloc_func(rbnng_MsgClass, msg_alloc);
59
- rb_define_method(rbnng_MsgClass, "body", msg_body, 0);
60
- rb_define_method(rbnng_MsgClass, "header", msg_header, 0);
61
- }
data/ext/rbnng/msg.h DELETED
@@ -1,22 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
-
6
- #ifndef RBNNG_MSG_H
7
- #define RBNNG_MSG_H
8
-
9
- #include <nng/nng.h>
10
- #include <ruby.h>
11
-
12
- extern VALUE rbnng_MsgClass;
13
-
14
- typedef struct
15
- {
16
- nng_msg* p_msg;
17
- } RbnngMsg;
18
-
19
- extern void
20
- rbnng_msg_Init(VALUE nng_module);
21
-
22
- #endif
data/ext/rbnng/pair.c DELETED
@@ -1,65 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/pair0/pair.h>
9
- #include <nng/protocol/pair1/pair.h>
10
- #include <ruby.h>
11
- #include <ruby/thread.h>
12
-
13
- static VALUE
14
- socket_pair0_initialize(VALUE self)
15
- {
16
- RbnngSocket* p_rbnngSocket;
17
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
18
- int rv;
19
- if ((rv = nng_pair0_open(&p_rbnngSocket->socket)) != 0) {
20
- raise_error(rv);
21
- return Qnil;
22
- }
23
-
24
- return self;
25
- }
26
-
27
- static VALUE
28
- socket_pair1_initialize(VALUE self)
29
- {
30
- RbnngSocket* p_rbnngSocket;
31
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
32
- int rv;
33
- if ((rv = nng_pair1_open(&p_rbnngSocket->socket)) != 0) {
34
- raise_error(rv);
35
- return Qnil;
36
- }
37
-
38
- return self;
39
- }
40
-
41
- void
42
- rbnng_pair_Init(VALUE nng_module)
43
- {
44
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
45
-
46
- VALUE rbnng_SocketPair1Class =
47
- rb_define_class_under(rbnng_SocketModule, "Pair1", rb_cObject);
48
- rb_define_alloc_func(rbnng_SocketPair1Class, socket_alloc);
49
- rb_define_method(
50
- rbnng_SocketPair1Class, "initialize", socket_pair1_initialize, 0);
51
- rb_define_method(rbnng_SocketPair1Class, "get_msg", socket_get_msg, 0);
52
- rb_define_method(rbnng_SocketPair1Class, "send_msg", socket_send_msg, 1);
53
- rb_define_method(rbnng_SocketPair1Class, "listen", socket_listen, 1);
54
- rb_define_method(rbnng_SocketPair1Class, "dial", socket_dial, 1);
55
-
56
- VALUE rbnng_SocketPair0Class =
57
- rb_define_class_under(rbnng_SocketModule, "Pair0", rb_cObject);
58
- rb_define_alloc_func(rbnng_SocketPair0Class, socket_alloc);
59
- rb_define_method(
60
- rbnng_SocketPair0Class, "initialize", socket_pair0_initialize, 0);
61
- rb_define_method(rbnng_SocketPair0Class, "get_msg", socket_get_msg, 0);
62
- rb_define_method(rbnng_SocketPair0Class, "send_msg", socket_send_msg, 1);
63
- rb_define_method(rbnng_SocketPair0Class, "listen", socket_listen, 1);
64
- rb_define_method(rbnng_SocketPair0Class, "dial", socket_dial, 1);
65
- }
data/ext/rbnng/pub0.c DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/pubsub0/pub.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_pub0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_pub0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- return self;
23
- }
24
-
25
- void
26
- rbnng_pub0_Init(VALUE nng_module)
27
- {
28
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
29
- VALUE rbnng_SocketPub0Class =
30
- rb_define_class_under(rbnng_SocketModule, "Pub0", rb_cObject);
31
- rb_define_alloc_func(rbnng_SocketPub0Class, socket_alloc);
32
- rb_define_method(
33
- rbnng_SocketPub0Class, "initialize", socket_pub0_initialize, 0);
34
- rb_define_method(rbnng_SocketPub0Class, "send_msg", socket_send_msg, 1);
35
- rb_define_method(rbnng_SocketPub0Class, "listen", socket_listen, 1);
36
- }
data/ext/rbnng/pull0.c DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/pipeline0/pull.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_pull0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_pull0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- return self;
23
- }
24
-
25
- void
26
- rbnng_pull0_Init(VALUE nng_module)
27
- {
28
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
29
- VALUE rbnng_SocketPull0Class =
30
- rb_define_class_under(rbnng_SocketModule, "Pull0", rb_cObject);
31
- rb_define_alloc_func(rbnng_SocketPull0Class, socket_alloc);
32
- rb_define_method(
33
- rbnng_SocketPull0Class, "initialize", socket_pull0_initialize, 0);
34
- rb_define_method(rbnng_SocketPull0Class, "get_msg", socket_get_msg, 0);
35
- rb_define_method(rbnng_SocketPull0Class, "listen", socket_listen, 1);
36
- }
data/ext/rbnng/push0.c DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/pipeline0/push.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_push0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_push0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- return self;
23
- }
24
-
25
- void
26
- rbnng_push0_Init(VALUE nng_module)
27
- {
28
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
29
- VALUE rbnng_SocketPush0Class =
30
- rb_define_class_under(rbnng_SocketModule, "Push0", rb_cObject);
31
- rb_define_alloc_func(rbnng_SocketPush0Class, socket_alloc);
32
- rb_define_method(
33
- rbnng_SocketPush0Class, "initialize", socket_push0_initialize, 0);
34
- rb_define_method(rbnng_SocketPush0Class, "send_msg", socket_send_msg, 1);
35
- rb_define_method(rbnng_SocketPush0Class, "dial", socket_dial, 1);
36
- }
data/ext/rbnng/rep0.c DELETED
@@ -1,150 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/reqrep0/rep.h>
9
- #include <ruby.h>
10
- #include <ruby/thread.h>
11
-
12
- static VALUE
13
- socket_rep0_listen(VALUE self, VALUE url)
14
- {
15
- Check_Type(url, T_STRING);
16
- int rv;
17
- RbnngSocket* p_rbnngSocket;
18
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
19
- if ((rv = nng_listen(p_rbnngSocket->socket, StringValueCStr(url), NULL, 0)) !=
20
- 0) {
21
- raise_error(rv);
22
- }
23
- }
24
-
25
- void*
26
- rep0_get_msg_blocking(RbnngSocket* p_rbnngSocket)
27
- {
28
- nng_aio* p_aio;
29
- int rv;
30
- if ((rv = nng_aio_alloc(&p_aio, 0, 0)) != 0) {
31
- return rv;
32
- }
33
-
34
- nng_ctx_recv(p_rbnngSocket->ctx, p_aio);
35
- nng_aio_wait(p_aio);
36
-
37
- if ((rv = nng_aio_result(p_aio)) != 0) {
38
- return rv;
39
- }
40
-
41
- nng_msg* p_msg = nng_aio_get_msg(p_aio);
42
- p_rbnngSocket->p_getMsgResult = p_msg;
43
- nng_aio_free(p_aio);
44
- return 0;
45
- }
46
-
47
- static VALUE
48
- socket_rep0_get_msg(VALUE self)
49
- {
50
- RbnngSocket* p_rbnngSocket;
51
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
52
- int rv =
53
- rb_thread_call_without_gvl(rep0_get_msg_blocking, p_rbnngSocket, 0, 0);
54
-
55
- if (rv == 0) {
56
- RbnngMsg* p_newMsg;
57
- VALUE newMsg = rb_class_new_instance(0, 0, rbnng_MsgClass);
58
- Data_Get_Struct(newMsg, RbnngMsg, p_newMsg);
59
- p_newMsg->p_msg = p_rbnngSocket->p_getMsgResult;
60
- return newMsg;
61
- } else {
62
- raise_error(rv);
63
- return Qnil;
64
- }
65
- }
66
-
67
- void*
68
- rep0_send_msg_blocking(void* data)
69
- {
70
- RbnngSendMsgReq* p_sendMsgReq = (RbnngSendMsgReq*)data;
71
- RbnngSocket* p_rbnngSocket;
72
- Data_Get_Struct(p_sendMsgReq->socketObj, RbnngSocket, p_rbnngSocket);
73
-
74
- nng_aio* p_aio;
75
- int rv;
76
- if ((rv = nng_aio_alloc(&p_aio, 0, 0)) != 0) {
77
- return rv;
78
- }
79
-
80
- nng_msg* p_msg;
81
- if ((rv = nng_msg_alloc(&p_msg, 0)) != 0) {
82
- return rv;
83
- }
84
-
85
- nng_msg_clear(p_msg);
86
- rv = nng_msg_append(p_msg,
87
- StringValuePtr(p_sendMsgReq->nextMsg),
88
- RSTRING_LEN(p_sendMsgReq->nextMsg));
89
- if (rv != 0) {
90
- return rv;
91
- }
92
-
93
- nng_aio_set_msg(p_aio, p_msg);
94
- nng_ctx_send(p_rbnngSocket->ctx, p_aio);
95
- nng_aio_wait(p_aio);
96
-
97
- if ((rv = nng_aio_result(p_aio)) != 0) {
98
- return rv;
99
- }
100
-
101
- nng_aio_free(p_aio);
102
- return 0;
103
- }
104
-
105
- static VALUE
106
- socket_rep0_send_msg(VALUE self, VALUE rb_strMsg)
107
- {
108
- Check_Type(rb_strMsg, T_STRING);
109
-
110
- RbnngSendMsgReq sendMsgReq = {
111
- .socketObj = self,
112
- .nextMsg = rb_strMsg,
113
- };
114
- int rv =
115
- rb_thread_call_without_gvl(rep0_send_msg_blocking, &sendMsgReq, 0, 0);
116
- if (rv != 0) {
117
- raise_error(rv);
118
- }
119
- }
120
-
121
- static VALUE
122
- socket_rep0_initialize(VALUE self)
123
- {
124
- RbnngSocket* p_rbnngSocket;
125
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
126
- int rv;
127
- if ((rv = nng_rep0_open(&p_rbnngSocket->socket)) != 0) {
128
- raise_error(rv);
129
- }
130
-
131
- if ((rv = nng_ctx_open(&p_rbnngSocket->ctx, p_rbnngSocket->socket)) != 0) {
132
- raise_error(rv);
133
- }
134
-
135
- return self;
136
- }
137
-
138
- void
139
- rbnng_rep0_Init(VALUE nng_module)
140
- {
141
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
142
- VALUE rbnng_SocketRep0Class =
143
- rb_define_class_under(rbnng_SocketModule, "Rep0", rb_cObject);
144
- rb_define_alloc_func(rbnng_SocketRep0Class, socket_alloc);
145
- rb_define_method(
146
- rbnng_SocketRep0Class, "initialize", socket_rep0_initialize, 0);
147
- rb_define_method(rbnng_SocketRep0Class, "get_msg", socket_rep0_get_msg, 0);
148
- rb_define_method(rbnng_SocketRep0Class, "send_msg", socket_rep0_send_msg, 1);
149
- rb_define_method(rbnng_SocketRep0Class, "listen", socket_rep0_listen, 1);
150
- }
data/ext/rbnng/req0.c DELETED
@@ -1,38 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/reqrep0/req.h>
9
- #include <ruby.h>
10
- #include <ruby/thread.h>
11
-
12
- static VALUE
13
- socket_req0_initialize(VALUE self)
14
- {
15
- RbnngSocket* p_rbnngSocket;
16
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
17
- int rv;
18
- if ((rv = nng_req0_open(&p_rbnngSocket->socket)) != 0) {
19
- raise_error(rv);
20
- return Qnil;
21
- }
22
-
23
- return self;
24
- }
25
-
26
- void
27
- rbnng_req0_Init(VALUE nng_module)
28
- {
29
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
30
- VALUE rbnng_SocketReq0Class =
31
- rb_define_class_under(rbnng_SocketModule, "Req0", rb_cObject);
32
- rb_define_alloc_func(rbnng_SocketReq0Class, socket_alloc);
33
- rb_define_method(
34
- rbnng_SocketReq0Class, "initialize", socket_req0_initialize, 0);
35
- rb_define_method(rbnng_SocketReq0Class, "get_msg", socket_get_msg, 0);
36
- rb_define_method(rbnng_SocketReq0Class, "send_msg", socket_send_msg, 1);
37
- rb_define_method(rbnng_SocketReq0Class, "dial", socket_dial, 1);
38
- }
@@ -1,40 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/survey0/respond.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_respondent0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_respondent0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- return self;
23
- }
24
-
25
- void
26
- rbnng_respondent0_Init(VALUE nng_module)
27
- {
28
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
29
- VALUE rbnng_SocketRespondent0Class =
30
- rb_define_class_under(rbnng_SocketModule, "Respondent0", rb_cObject);
31
- rb_define_alloc_func(rbnng_SocketRespondent0Class, socket_alloc);
32
- rb_define_method(rbnng_SocketRespondent0Class,
33
- "initialize",
34
- socket_respondent0_initialize,
35
- 0);
36
- rb_define_method(
37
- rbnng_SocketRespondent0Class, "send_msg", socket_send_msg, 1);
38
- rb_define_method(rbnng_SocketRespondent0Class, "get_msg", socket_get_msg, 0);
39
- rb_define_method(rbnng_SocketRespondent0Class, "dial", socket_dial, 1);
40
- }
data/ext/rbnng/socket.h DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
-
6
- #ifndef RBNNG_SOCKET_H
7
- #define RBNNG_SOCKET_H
8
-
9
- #include <nng/nng.h>
10
- #include <pthread.h>
11
- #include <ruby.h>
12
- #include <stdbool.h>
13
-
14
- typedef struct
15
- {
16
- nng_socket socket;
17
- // Not all socket types will use a context
18
- nng_ctx ctx;
19
-
20
- // for get_msg
21
- nng_msg* p_getMsgResult;
22
- } RbnngSocket;
23
-
24
- typedef struct
25
- {
26
- VALUE socketObj; // A socket class instnace
27
- VALUE nextMsg; // Ruby string
28
- } RbnngSendMsgReq;
29
-
30
- extern VALUE socket_alloc(VALUE);
31
- extern VALUE socket_get_msg(VALUE);
32
- extern VALUE socket_send_msg(VALUE, VALUE);
33
- extern VALUE socket_dial(VALUE, VALUE);
34
- extern VALUE socket_listen(VALUE, VALUE);
35
-
36
- #endif
data/ext/rbnng/sub0.c DELETED
@@ -1,41 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
- */
5
- #include "msg.h"
6
- #include "rbnng.h"
7
- #include "socket.h"
8
- #include <nng/protocol/pubsub0/sub.h>
9
- #include <ruby.h>
10
-
11
- static VALUE
12
- socket_sub0_initialize(VALUE self)
13
- {
14
- RbnngSocket* p_rbnngSocket;
15
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
16
- int rv;
17
- if ((rv = nng_sub0_open(&p_rbnngSocket->socket)) != 0) {
18
- raise_error(rv);
19
- return Qnil;
20
- }
21
-
22
- if ((rv = nng_socket_set(p_rbnngSocket->socket, NNG_OPT_SUB_SUBSCRIBE, "", 0)) != 0) {
23
- raise_error(rv);
24
- return Qnil;
25
- }
26
-
27
- return self;
28
- }
29
-
30
- void
31
- rbnng_sub0_Init(VALUE nng_module)
32
- {
33
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
34
- VALUE rbnng_SocketSub0Class =
35
- rb_define_class_under(rbnng_SocketModule, "Sub0", rb_cObject);
36
- rb_define_alloc_func(rbnng_SocketSub0Class, socket_alloc);
37
- rb_define_method(
38
- rbnng_SocketSub0Class, "initialize", socket_sub0_initialize, 0);
39
- rb_define_method(rbnng_SocketSub0Class, "get_msg", socket_get_msg, 0);
40
- rb_define_method(rbnng_SocketSub0Class, "dial", socket_dial, 1);
41
- }
@@ -1,40 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Adib Saad
3
- *
4
-
5
- // NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50));
6
- // NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 100));
7
- */
8
- #include "msg.h"
9
- #include "rbnng.h"
10
- #include "socket.h"
11
- #include <nng/protocol/survey0/survey.h>
12
- #include <ruby.h>
13
-
14
- static VALUE
15
- socket_surveyor0_initialize(VALUE self)
16
- {
17
- RbnngSocket* p_rbnngSocket;
18
- Data_Get_Struct(self, RbnngSocket, p_rbnngSocket);
19
- int rv;
20
- if ((rv = nng_surveyor0_open(&p_rbnngSocket->socket)) != 0) {
21
- raise_error(rv);
22
- return Qnil;
23
- }
24
-
25
- return self;
26
- }
27
-
28
- void
29
- rbnng_surveyor0_Init(VALUE nng_module)
30
- {
31
- VALUE rbnng_SocketModule = rb_define_module_under(nng_module, "Socket");
32
- VALUE rbnng_SocketSurveyor0Class =
33
- rb_define_class_under(rbnng_SocketModule, "Surveyor0", rb_cObject);
34
- rb_define_alloc_func(rbnng_SocketSurveyor0Class, socket_alloc);
35
- rb_define_method(
36
- rbnng_SocketSurveyor0Class, "initialize", socket_surveyor0_initialize, 0);
37
- rb_define_method(rbnng_SocketSurveyor0Class, "send_msg", socket_send_msg, 1);
38
- rb_define_method(rbnng_SocketSurveyor0Class, "get_msg", socket_get_msg, 0);
39
- rb_define_method(rbnng_SocketSurveyor0Class, "listen", socket_listen, 1);
40
- }