84件ヒット
[1-84件を表示]
(0.009秒)
キーワード
- ConditionVariable (12)
- IO (12)
- Monitor (12)
- ShiftingError (12)
- String (12)
- TCPServer (12)
- TCPSocket (12)
検索結果
-
Logger
:: ShiftingError (6001.0) -
ログファイルの切り替えに失敗した場合に発生する例外です。
ログファイルの切り替えに失敗した場合に発生する例外です。 -
TCPServer (13.0)
-
TCP/IP ストリーム型接続のサーバ側のソケットのクラスです。
...例えば echo サーバは以下のようになります。
require "socket"
gs = TCPServer.open(0)
socks = [gs]
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
while true
nsock = select(socks)
next if nsock == nil
for s in nsock[0]
if s......end
end
end
Thread を使えばもっと短くなります。
require "socket"
gs = TCPServer.open(0)
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
while true
Thread.start(gs.accept) do |s| # save to dynamic variable
print(s, "... -
IO (7.0)
-
基本的な入出力機能のためのクラスです。
...の方法を使います。
例1:
f = File.open('file1')
p f.getc.encoding #=> Encoding::EUC_JP
例2:
f = File.open('t.txt', 'w+:shift_jis:euc-jp')
f.write "\xB4\xC1\xBB\xFA" # 文字列 "漢字" の EUC-JP リテラル
f.rewind
s = f.read(4)
puts s.dump... -
Monitor (7.0)
-
スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。
...w
empty_cond = mon.new_cond
# consumer
Thread.start do
loop do
mon.synchronize do
empty_cond.wait_while { buf.empty? }
print buf.shift
end
end
end
# producer
while line = ARGF.gets
mon.synchronize do
buf.push(line)
empty_cond.signal
end
end
//}
2回ロックし... -
String (7.0)
-
文字列のクラスです。 ヌル文字を含む任意のバイト列を扱うことができます。 文字列の長さにはメモリ容量以外の制限はありません。
...従って UTF-16 はASCII互換ではありません。
また厳密性を追求せず、おおむね互換なら互換と呼びます。よって Shift_JIS は ASCII 互換です。
==== バイト列を表す文字列
文字列ではない単なるバイト列も String オブジェクトで表... -
TCPSocket (7.0)
-
インターネットドメインのストリーム型ソケットのクラスです。
...をそのままサーバに転送するプログラムは以下の
ようになります。
require "socket"
port = if ARGV.size > 0 then ARGV.shift else 4444 end
print port, "\n"
s = TCPSocket.open("localhost", port)
while gets
s.write($_)
print(s.gets)
end
s.close... -
Thread
:: ConditionVariable (7.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。
require 'thread'
class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex = Mut......@empty.signal if count == 1
}
end
def deq
@mutex.synchronize{
@empty.wait(@mutex) if count == 0
v = @q.shift
@full.signal if count == (@max - 1)
v
}
end
alias send enq
alias recv deq
end
if __FILE__ == $0
q = Ti...