Returns the base 2 logarithm of x
.
Domain: (0, INFINITY)
Codomain: (-INFINITY, INFINITY)
Math.log2(1) #=> 0.0 Math.log2(2) #=> 1.0 Math.log2(32768) #=> 15.0 Math.log2(65536) #=> 16.0
Returns the base 10 logarithm of x
.
Domain: (0, INFINITY)
Codomain: (-INFINITY, INFINITY)
Math.log10(1) #=> 0.0 Math.log10(10) #=> 1.0 Math.log10(10**100) #=> 100.0
creates a TCP/IP server on port and calls the block for each connection accepted. The block is called with a socket and a client_address as an Addrinfo
object.
If host is specified, it is used with port to determine the server addresses.
The socket is not closed when the block returns. So application should close it explicitly.
This method calls the block sequentially. It means that the next connection is not accepted until the block returns. So concurrent mechanism, thread for example, should be used to service multiple clients at a time.
Note that Addrinfo.getaddrinfo
is used to determine the server socket addresses. When Addrinfo.getaddrinfo
returns two or more addresses, IPv4 and IPv6 address for example, all of them are used. Socket.tcp_server_loop
succeeds if one socket can be used at least.
# Sequential echo server. # It services only one client at a time. Socket.tcp_server_loop(16807) {|sock, client_addrinfo| begin IO.copy_stream(sock, sock) ensure sock.close end } # Threaded echo server # It services multiple clients at a time. # Note that it may accept connections too much. Socket.tcp_server_loop(16807) {|sock, client_addrinfo| Thread.new { begin IO.copy_stream(sock, sock) ensure sock.close end } }
creates a UDP/IP server on port and calls the block for each message arrived. The block is called with the message and its source information.
This method allocates sockets internally using port. If host is specified, it is used conjunction with port to determine the server addresses.
The msg is a string.
The msg_src is a Socket::UDPSource
object. It is used for reply.
# UDP/IP echo server. Socket.udp_server_loop(9261) {|msg, msg_src| msg_src.reply msg }
creates a UNIX socket server on path. It calls the block for each socket accepted.
If host is specified, it is used with port to determine the server ports.
The socket is not closed when the block returns. So application should close it.
This method deletes the socket file pointed by path at first if the file is a socket file and it is owned by the user of the application. This is safe only if the directory of path is not changed by a malicious user. So don’t use /tmp/malicious-users-directory/socket. Note that /tmp/socket and /tmp/your-private-directory/socket is safe assuming that /tmp has sticky bit.
# Sequential echo server. # It services only one client at a time. Socket.unix_server_loop("/tmp/sock") {|sock, client_addrinfo| begin IO.copy_stream(sock, sock) ensure sock.close end }
Finds the appropriate virtual host to handle req
Is code
a server error status?
Is code
a server error status?
Run UDP/IP server loop on the given sockets.
The return value of Socket.udp_server_sockets
is appropriate for the argument.
It calls the block for each message received.
Creates a new Socket::Option
object for SOL_SOCKET/SO_LINGER.
onoff should be an integer or a boolean.
secs should be the number of seconds.
p Socket::Option.linger(true, 10) #=> #<Socket::Option: UNSPEC SOCKET LINGER on 10sec>
Returns the linger data in sockopt as a pair of boolean and integer.
sockopt = Socket::Option.linger(true, 10) p sockopt.linger => [true, 10]
Logs in to the remote host. The session must have been previously connected. If user
is the string “anonymous” and the password
is nil
, “anonymous@” is used as a password. If the acct
parameter is not nil
, an FTP
ACCT command is sent following the successful login. Raises an exception on error (typically Net::FTPPermError
).
Sends a LOGOUT command to inform the server that the client is done with the connection.
Sends a LOGIN command to identify the client and carries the plaintext password
authenticating this user
. Note that, unlike calling authenticate()
with an auth_type
of “LOGIN”, login()
does not use the login authenticator.
A Net::IMAP::NoResponseError
is raised if authentication fails.
Creates a singleton RingFinger
and looks for a RingServer
. Returns the created RingFinger
.
Merges the requirements of other
into this dependency
oth
URI
or String
Destructive form of merge
require 'uri' uri = URI.parse("http://my.example.com") uri.merge!("/main.rbx?page=1") p uri # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
oth
URI
or String
Merges two URI’s.
require 'uri' uri = URI.parse("http://my.example.com") p uri.merge("/main.rbx?page=1") # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
Logs data
at level
if the given level is above the current log level.
Same as BasicLog#log
Translates and dispatches Windows message.