Class: Socket
- Inherits:
-
BasicSocket
show all
- Includes:
- Constants
- Defined in:
- mrbgems/mruby-socket/src/socket.c,
mrbgems/mruby-socket/mrblib/socket.rb,
mrbgems/mruby-socket/mrblib/socket.rb,
mrbgems/mruby-socket/mrblib/socket.rb
Overview
Defined Under Namespace
Modules: Constants
Classes: Option
Constant Summary
Constants inherited
from IO
IO::BUF_SIZE, IO::SEEK_CUR, IO::SEEK_END, IO::SEEK_SET
Instance Attribute Summary
Attributes inherited from BasicSocket
#do_not_reverse_lookup
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BasicSocket
#_is_socket=, #_recvfrom, #_setnonblock, #close, do_not_reverse_lookup, do_not_reverse_lookup=, for_fd, #getpeereid, #getpeername, #getsockname, #getsockopt, #local_address, #recv, #recv_nonblock, #remote_address, #send, #setsockopt, #shutdown, #sysread, #sysseek, #syswrite
Methods inherited from IO
#<<, #_check_readable, #_read_buf, #close, #close_on_exec=, #close_on_exec?, #close_write, #closed?, #each, #each_byte, #eof?, #fileno, #flush, #getc, #gets, #hash, #initialize_copy, #isatty, #pid, pipe, popen, #pos, #pos=, #print, #printf, #puts, read, #read, #readchar, #readline, #readlines, #rewind, #seek, #sync, #sync=, #sysread, #sysseek, #syswrite, #ungetc, #write
Constructor Details
#initialize(domain, type, protocol = 0) ⇒ Socket
Returns a new instance of Socket
354
355
356
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 354
def initialize(domain, type, protocol=0)
super(Socket._socket(domain, type, protocol), "r+")
end
|
Class Method Details
.getaddrinfo(nodename, servname, family = nil, socktype = nil, protocol = nil, flags = 0) ⇒ Object
360
361
362
363
364
365
366
367
368
369
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 360
def self.getaddrinfo(nodename, servname, family=nil, socktype=nil, protocol=nil, flags=0)
Addrinfo.getaddrinfo(nodename, servname, family, socktype, protocol, flags).map { |ai|
ary = ai._to_array
ary[2] = nodename
ary[4] = ai.afamily
ary[5] = ai.socktype
ary[6] = ai.protocol
ary
}
end
|
.open(*args) ⇒ Object
def self.getnameinfo
def self.ip_address_list
374
375
376
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 374
def self.open(*args)
new(args)
end
|
.sockaddr_in(port, host) ⇒ Object
Also known as:
pack_sockaddr_in
378
379
380
381
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 378
def self.sockaddr_in(port, host)
ai = Addrinfo.getaddrinfo(host, port, nil, Socket::SOCK_DGRAM)[0]
ai.to_sockaddr
end
|
.unpack_sockaddr_in(sa) ⇒ Object
def self.tcp
def self.tcp_server_loop
def self.tcp_server_sockets
def self.udp_server_loop
def self.udp_server_loop_on
def self.udp_server_recv
def self.udp_server_sockets
def self.unix(path)
def self.unix_server_loop
def self.unix_server_socket
394
395
396
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 394
def self.unpack_sockaddr_in(sa)
Addrinfo.new(sa).ip_unpack.reverse
end
|
.unpack_sockaddr_un(sa) ⇒ Object
398
399
400
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 398
def self.unpack_sockaddr_un(sa)
Addrinfo.new(sa).unix_path
end
|
Instance Method Details
#accept ⇒ Object
408
409
410
411
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 408
def accept
fd, addr = self.sysaccept
[ Socket.for_fd(fd), addr ]
end
|
#accept_nonblock ⇒ Object
413
414
415
416
417
418
419
420
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 413
def accept_nonblock
begin
self._setnonblock(true)
self.accept
ensure
self._setnonblock(false)
end
end
|
#bind(sockaddr) ⇒ Object
422
423
424
425
426
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 422
def bind(sockaddr)
sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
Socket._bind(self.fileno, sockaddr)
0
end
|
#connect(sockaddr) ⇒ Object
428
429
430
431
432
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 428
def connect(sockaddr)
sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
Socket._connect(self.fileno, sockaddr)
0
end
|
#connect_nonblock(sockaddr) ⇒ Object
434
435
436
437
438
439
440
441
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 434
def connect_nonblock(sockaddr)
begin
self._setnonblock(true)
self.connect(sockaddr)
ensure
self._setnonblock(false)
end
end
|
#listen(backlog) ⇒ Object
445
446
447
448
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 445
def listen(backlog)
Socket._listen(self.fileno, backlog)
0
end
|
#recvfrom(maxlen, flags = 0) ⇒ Object
450
451
452
453
454
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 450
def recvfrom(maxlen, flags=0)
msg, sa = _recvfrom(maxlen, flags)
socktype = self.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE).int
[ msg, Addrinfo.new(sa, Socket::PF_UNSPEC, socktype) ]
end
|
#recvfrom_nonblock(*args) ⇒ Object
456
457
458
459
460
461
462
463
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 456
def recvfrom_nonblock(*args)
begin
self._setnonblock(true)
self._recvfrom(*args)
ensure
self._setnonblock(false)
end
end
|
#sysaccept ⇒ Object
465
466
467
|
# File 'mrbgems/mruby-socket/mrblib/socket.rb', line 465
def sysaccept
Socket._accept2(self.fileno)
end
|