Added complete call-seq documentation for socket programming methods across all major socket classes in both mrblib/socket.rb (64 Ruby methods) and src/socket.c (35 C methods): - Addrinfo: Complete documentation for address information handling including creation (new, foreach, ip, tcp, udp, unix), inspection (inspect, inspect_sockaddr, to_s), address queries (afamily, pfamily, ipv4?, ipv6?, ip?, unix?), data extraction (ip_address, ip_port, ip_unpack, unix_path), and conversion methods (to_sockaddr, getnameinfo) - BasicSocket: Core socket functionality including class configuration (do_not_reverse_lookup, do_not_reverse_lookup=), object creation (for_fd), address retrieval (local_address, remote_address), and non-blocking operations (recv_nonblock) - IPSocket: Internet protocol socket operations including address information (addr, peeraddr), connection methods (bind, connect), data transfer (send, recvfrom, recvfrom_nonblock), and address resolution (getaddress) - TCPSocket/TCPServer: TCP client and server socket operations including connection establishment (new, open), server operations (accept, accept_nonblock, listen, sysaccept) - UDPSocket: UDP socket operations for datagram communication including initialization and internal address handling - Socket: Low-level socket operations including creation (new, open), address manipulation (sockaddr_in, sockaddr_un, unpack_sockaddr_in, unpack_sockaddr_un), connection management (bind, connect, listen), data transfer (recvfrom, recvfrom_nonblock), socket pairs (pair), and name resolution (getaddrinfo, getnameinfo) - UNIXSocket/UNIXServer: Unix domain socket operations for local IPC including creation (new, socketpair), path handling (path, addr, peeraddr), server operations (accept, accept_nonblock, listen, sysaccept), and data transfer (recvfrom) - Addrinfo: Core address resolution methods including getaddrinfo for name resolution, getnameinfo for reverse lookups, and unix_path for Unix domain socket paths - BasicSocket: Low-level socket operations including getpeereid for peer credentials, getpeername/getsockname for address retrieval, recv/send for data transfer, getsockopt/setsockopt for option management, shutdown for connection termination, and Windows-specific overrides (close, sysread, sysseek, syswrite) - IPSocket: Internet protocol utilities including ntop/pton for address conversion and recvfrom for receiving data with sender information - Socket: Core socket creation and management including gethostname, internal methods (_accept, _bind, _connect, _listen, _socket), address utilities (sockaddr_un, socketpair), and platform-specific implementations - Socket::Option: Socket option handling including creation from boolean/ integer values, accessor methods (family, level, optname, data), type conversion (int, bool), and debugging support (inspect) All methods now have comprehensive call-seq documentation with practical This significantly improves maintainability and usability of errno handling for developers working with system call errors and file operations in embedded Ruby environments. Co-authored-by: Atlassian Rovo Dev
mruby-socket
"mruby-socket" mrbgem provides BSD socket interface for mruby. API is compatible with CRuby's "socket" library.
Example
% vi kame.rb
s = TCPSocket.open("www.kame.net", 80)
s.write("GET / HTTP/1.0\r\n\r\n")
puts s.read
s.close
% mruby kame.rb
HTTP/1.1 200 OK
Date: Tue, 21 May 2013 04:31:30 GMT
...
Requirement
- mruby-io mrbgem
- iij/mruby-mtest mrbgem to run tests
- system must have RFC3493 basic socket interface
- and some POSIX API...
TODO
- add missing methods
- write more tests
- fix possible descriptor leakage (see XXX comments)
UNIXSocket#recv_ioUNIXSocket#send_io
License
Copyright (c) 2013 Internet Initiative Japan Inc. Copyright (c) 2017 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.