/* * call-seq: * unixserver.sysaccept => file_descriptor * * Accepts a new connection. * It returns the new file descriptor which is an integer. * * UNIXServer.open("/tmp/sock") {|serv| * UNIXSocket.open("/tmp/sock") {|c| * fd = serv.sysaccept * s = IO.new(fd) * s.puts "hi" * s.close * p c.read #=> "hi\n" * } * } * */ static VALUE unix_sysaccept(VALUE sock) { rb_io_t *fptr; struct sockaddr_un from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = (socklen_t)sizeof(struct sockaddr_un); return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen); }
/* * call-seq: * tcpserver.sysaccept => file_descriptor * * Returns a file descriptor of a accepted connection. * * TCPServer.open("127.0.0.1", 28561) {|serv| * fd = serv.sysaccept * s = IO.for_fd(fd) * s.puts Time.now * s.close * } * */ static VALUE tcp_sysaccept(VALUE sock) { rb_io_t *fptr; union_sockaddr from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = (socklen_t)sizeof(from); return rsock_s_accept(0, fptr->fd, &from.addr, &fromlen); }
/* * call-seq: * tcpserver.sysaccept => file_descriptor * * Returns a file descriptor of a accepted connection. * * TCPServer.open("127.0.0.1", 28561) {|serv| * fd = serv.sysaccept * s = IO.for_fd(fd) * s.puts Time.now * s.close * } * */ static VALUE tcp_sysaccept(VALUE sock) { rb_io_t *fptr; struct sockaddr_storage from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = sizeof(from); return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen); }