Project

General

Profile

Feature #2250 ยป syssocket.c

pilcrow (Mike Pomraning), 10/22/2009 12:43 PM

 
1
#include <ruby.h>
2
#include <unistd.h>
3
#include <sys/types.h>
4
#include <sys/socket.h>
5

    
6
static VALUE
7
io_syssocket(VALUE klass, VALUE domain, VALUE type, VALUE protocol)
8
{
9
	int s;
10

    
11
	s = socket(NUM2INT(domain), NUM2INT(type), NUM2INT(protocol));
12
	if (s < 0) rb_sys_fail("socket");
13
	return INT2FIX(s);
14
}
15

    
16
static VALUE
17
io_sysclose(VALUE klass, VALUE fd)
18
{
19
	int r;
20

    
21
	r = close(NUM2INT(fd));
22
	if (r < 0) rb_sys_fail("sysclose");
23

    
24
	return INT2FIX(r);
25
}
26

    
27
void
28
Init_iosyssocket()
29
{
30
	rb_define_singleton_method(rb_cIO, "syssocket", io_syssocket, 3);
31
	rb_define_singleton_method(rb_cIO, "sysclose", io_sysclose, 1);
32
}