Class: NanoMsg::Socket
- Inherits:
-
Object
show all
- Defined in:
- lib/nanomsg.rb,
ext/init.c
Instance Method Summary
collapse
Instance Method Details
#bind(bind) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'ext/init.c', line 118
static VALUE
sock_bind(VALUE socket, VALUE bind)
{
int sock = sock_get(socket);
int endpoint;
endpoint = nn_bind(sock, StringValueCStr(bind));
if (endpoint < 0)
RAISE_SOCK_ERROR;
// TODO do something with the endpoint, returning it in a class for example.
return Qnil;
}
|
#close ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'ext/init.c', line 237
static VALUE
sock_close(VALUE socket)
{
struct ioop io;
io.sock = sock_get(socket);
// I've no idea on how to abort a close (which may block for NN_LINGER
// seconds), so we'll be uninterruptible.
rb_thread_blocking_region(sock_close_no_gvl, &io, RUBY_UBF_IO, 0);
if (io.return_code < 0)
sock_raise_error(io.nn_errno);
return Qnil;
}
|
#connect(connect) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'ext/init.c', line 132
static VALUE
sock_connect(VALUE socket, VALUE connect)
{
int sock = sock_get(socket);
int endpoint;
endpoint = nn_connect(sock, StringValueCStr(connect));
if (endpoint < 0)
RAISE_SOCK_ERROR;
// TODO do something with the endpoint, returning it in a class for example.
return Qnil;
}
|
#recv ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'ext/init.c', line 206
static VALUE
sock_recv(VALUE socket)
{
VALUE result;
struct ioop io;
io.sock = sock_get(socket);
rb_thread_blocking_region(sock_recv_blocking, &io, RUBY_UBF_IO, 0);
if (io.return_code < 0)
sock_raise_error(io.nn_errno);
result = rb_str_new(io.buffer, io.return_code);
nn_freemsg(io.buffer); io.buffer = (char*) 0;
return result;
}
|
#send(buffer) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'ext/init.c', line 176
static VALUE
sock_send(VALUE socket, VALUE buffer)
{
struct ioop io;
io.sock = sock_get(socket);
io.buffer = StringValuePtr(buffer);
io.len = RSTRING_LEN(buffer);
rb_thread_blocking_region(sock_send_blocking, &io, RUBY_UBF_IO, 0);
if (io.return_code < 0)
sock_raise_error(io.nn_errno);
return INT2NUM(io.return_code);
}
|
#setsockopt(level, option, val) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'ext/init.c', line 254
static VALUE
sock_setsockopt(VALUE self, VALUE level, VALUE option, VALUE val)
{
int sock = sock_get(self);
int level_arg = FIX2INT(level);
int option_arg = FIX2INT(option);
int err;
int i;
void* v;
size_t vlen = 0;
switch (TYPE(val)) {
case T_FIXNUM:
i = FIX2INT(val);
goto numval;
case T_FALSE:
i = 0;
goto numval;
case T_TRUE:
i = 1;
numval:
v = (void*)&i; vlen = sizeof(i);
break;
default:
StringValue(val);
v = RSTRING_PTR(val);
vlen = RSTRING_LEN(val);
break;
}
err = nn_setsockopt(sock, level_arg, option_arg, v, vlen);
if (err < 0)
RAISE_SOCK_ERROR;
return self;
}
|