=encoding euc-jp =head1 NAME =begin original Net::Server::Proto - adp0 - Net::Server Protocol compatibility layer =end original Net::Server::Proto - adp0 - Net::Server プロトコル互換レイヤー =head1 概要 # Net::Server::Protoと付属のモジュールは、Net::Serverの # スコープの外で利用されることを意図していない。 # このモジュールは、他のセットを含むようにプロトコルを # 拡張(例えばデータベースコネクションプロトコル)したい # 人のためにのみある。 use Net::Server::Proto; my $sock = Net::Server::Proto->object( $default_host, # portに指定されていない場合のホスト $port, # 接続ポート $default_proto, # portに指定されていない場合のプロトコル $server_obj, # Net::Serverオブジェクト ); ### Net::Server::ProtoはNet::Server::Proto::TCPと同じ名前の ### サブモジュールへのインターフェースを試みる。 ### 個々のサブモジュールは、それらが必要なときに ### Net::Server::Protoによってロードされる。 use Net::Server::Proto::TCP; # TCP/UDP/UNIX/等々 ### IO::Socketのサブクラスオブジェクトを返す。 ### この時点ではオブジェクトは接続されていない。 ### このメソッドはサーバオブジェクトから必要とする ### 何らかの情報を集めることができる。 my $sock = Net::Server::Proto::TCP->object( $default_host, # portに指定されていない場合のホスト $port, # 接続ポート $server_obj, # Net::Serverオブジェクト ); ### 接続開始時のログをとる。 ### 渡されたNet::Serverオブジェクトの機能を利用する。 $sock->log_connect( $server ); ### 実際にポートないしはソケットファイルにbindする。 ### これは典型的には設定メソッドを呼び出してなされる。 $sock->connect(); ### すでに開かれたfilenoに対して再度bindを可能にする。 ### 典型的にはfdopenするだけである。 $sock->reconnect(); ### 再接続時に利用されるこのソケットに対する ### 一意な識別文字列を返す。 my $str = $sock->hup_string(); ### このモジュールが利用するプロトコルを返す。 my $proto = $sock->NS_proto(); =head1 説明 =begin original Net::Server::Proto is an intermediate module which returns IO::Socket style objects blessed into its own set of classes (ie Net::Server::Proto::TCP, Net::Server::Proto::UNIX). =end original Net::Server::Protoは、それ自身のクラスセット(すなわち、 Net::Server::Proto::TCP、Net::Server::Proto::UNIX)に blessされたIO::Socket型オブジェクトを返す媒介モジュールである。 =begin original Only three or four protocols come bundled with Net::Server. TCP, UDP, UNIX, and eventually SSL. TCP is an implementation of SOCK_STREAM across an INET socket. UDP is an implementation of SOCK_DGRAM across an INET socket. UNIX uses a unix style socket file and lets the user choose between SOCK_STREAM and SOCK_DGRAM (the default is SOCK_STREAM). SSL is actually just a layer on top of TCP. =end original Net::Serverには3〜4個のプロトコルがバンドルされているだけだ。 TCP、UDP、UNIX、そして最後にSSL。TCPはINETソケットを横断する SCOK_STREAMの実装である。UDPはINETソケットを横断する SOCK_DGRAMの実装。UNIXはunix型ソケットファイルを利用し、 ユーザーはSOCK_STREAMとSOCK_DGRAMから選ぶことが出来る (デフォルトはSOCK_STREAM)。SSLはTCPの最上層のレイヤーである。 =begin original The protocol that is passed to Net::Server can be the name of another module which contains the protocol bindings. If a protocol of MyServer::MyTCP was passed, the socket would be blessed into that class. If Net::Server::Proto::TCP was passed, it would get that class. If a bareword, such as tcp, udp, unix or ssl, is passed, the word is uppercased, and post pended to "Net::Server::Proto::" (ie tcp = Net::Server::Proto::TCP). =end original Net::Serverに渡されるプロトコルはプロトコルバインディングを 含む別のモジュール名にすることができる。もしMyServer::MyTCP というプロトコルが渡されれば、ソケットはそのクラスにbless される。もしNet::Server::Proto::TCPが渡されれば、そのクラスを 取得する。もし裸のワード、例えばtcp、udp、unix、あるいはsslの ような単語が渡されると、その単語は大文字にされ、 "Net::Server::Proto::"の後ろにつけられる (つまり、tcp=Net::Server::Proto::TCP)。 =head1 メソッド =begin original Protocol names used by the Net::Server::Proto should be sub classes of IO::Socket. These classes should also contain, as a minimum, the following methods: =end original Net::Server::Protoによって使われるプロトコル名は、IO::Socketの サブクラスであるべきだ。また、これらのクラスは、最低でも次の メソッドを含むべきである。 =over 4 =item object =begin original Return an object which is a sub class of IO::Socket At this point the object is not connected. The method can gather any other information that it needs from the server object. Arguments are default_host, port, and a Net::Server style server object. =end original IO::Socketのサブクラスのオブジェクトを返す。 この時点ではオブジェクトは接続されていない。メソッドは サーバオブジェクトから必要とする何らかの情報を集める ことができる。引数はdefault_host、port、そして Net::Server型のサーバオブジェクトである。 =item log_connect =begin original Log that a connection is about to occur. Use the facilities of the passed Net::Server object. This should be an informative string explaining which properties are being used. =end original 生じた接続をログに書き込む。渡されたNet::Serverオブジェクト の機能を利用する。これは使われるプロパティを説明するような 有益な文字列であるべきだ。 =item connect =begin original Actually bind to port or socket file. This is typically done internally by calling the configure method of the IO::Socket super class. =end original ポートかソケットファイルに実際にbindする。これは典型的には、 内部でIO::Secketのスーパークラスの設定用メソッドを呼び出す ことによって実行される。 =item reconnect =begin original Allow for rebinding to an already open fileno. Typically will just do an fdopen using the IO::Socket super class. =end original 既に開いてあるfilenoに再度bindすることを許可する。 典型的には、IO::Socketのスーパークラスを利用して、 fdopenする。 =item hup_string =begin original Return a unique identifying string for this sock that can be used when reconnecting. This is done to allow information including the file descriptor of the open sockets to be passed via %ENV during an exec. This string should always be the same based upon the configuration parameters. =end original 再接続する際に利用されうるソケットに対する一意な識別文字列を 返す。execの際に%ENVを通じて渡される、開かれたソケットの ファイル記述子を含んだ情報を可能にする。この文字列は 常に設定用パラメータに基づいて同じようになるべきである。 =item NS_proto =begin original Net::Server protocol. Return the protocol that is being used by this module. This does not have to be a registered or known protocol. =end original Net::Serverのプロトコル。このモジュールによって利用される プロトコルを返す。これは、登録されていたり、よく知られて いるプロトコルである必要はない。 =item show =begin original Similar to log_connect, but simply shows a listing of which properties were found. Can be used at any time. =end original log_connectと同じだが、見つけられたプロパティをリスト表示する だけである。いつでも使うことができる。 =back =head1 ポート =begin original The port is the most important argument passed to the sub module classes and to Net::Server::Proto itself. For tcp, udp, and ssl style ports, the form is generally host:port/protocol, host|port|protocol, host/port, or port. For unix the form is generally socket_file|type|unix or socket_file. =end original ポートは、サブクラスのモジュールとNet::Server::Protoそれ自身に 渡される引数の中でも最も重要なものだ。tcp、udp、そしてsslタイプ のポートにおいて、その書式は一般的に host:port/protocol、 host|port|protocol、host/port、あるいは port となる。 unixでは socket_file|type|unix か socket_file になる。 =begin original You can see what Net::Server::Proto parsed out by looking at the logs to see what log_connect said. You could also include a post_bind_hook similar to the following to debug what happened: =end original ログを見ればlog_connectが吐き出すものを知ることができるが、 それによりNet::Server::Protoが何を解析しているかわかるだろう。 sub post_bind_hook { my $self = shift; foreach my $sock ( @{ $self->{server}->{sock} } ){ $self->log(2,$sock->show); } } =begin original Rather than try to explain further, please look at the following examples: =end original 詳しく説明するより、次のサンプルを見るほうがよろしかろう。 # example 1 ################################### $port = "20203"; $def_host = "default_domain.com"; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::TCP # NS_host = default_domain.com # NS_port = 20203 # NS_proto = TCP # example 2 ################################### $port = "someother.com:20203"; $def_host = "default_domain.com"; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::TCP # NS_host = someother.com # NS_port = 20203 # NS_proto = TCP # example 3 ################################### $port = "someother.com:20203/udp"; $def_host = "default_domain.com"; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::UDP # NS_host = someother.com # NS_port = 20203 # NS_proto = UDP # example 4 ################################### $port = "someother.com:20203/Net::Server::Proto::UDP"; $def_host = "default_domain.com"; $def_proto = "TCP"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::UDP # NS_host = someother.com # NS_port = 20203 # NS_proto = UDP # example 5 ################################### $port = "someother.com:20203/MyObject::TCP"; $def_host = "default_domain.com"; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = MyObject::TCP # NS_host = someother.com # NS_port = 20203 # NS_proto = TCP (depends on MyObject::TCP module) # example 6 ################################### $port = "/tmp/mysock.file|unix"; $def_host = "default_domain.com"; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::UNIX # NS_host = undef # NS_port = undef # NS_unix_path = /tmp/mysock.file # NS_unix_type = SOCK_STREAM # NS_proto = UNIX # example 7 ################################### $port = "/tmp/mysock.file|".SOCK_DGRAM."|unix"; $def_host = ""; $def_proto = "tcp"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::UNIX # NS_host = undef # NS_port = undef # NS_unix_path = /tmp/mysock.file # NS_unix_type = SOCK_DGRAM # NS_proto = UNIX # example 8 ################################### $port = "/tmp/mysock.file|".SOCK_DGRAM."|unix"; $def_host = ""; $def_proto = "UNIX"; $obj = Net::Server::Proto->object($def_host,$port,$def_proto); # ref = Net::Server::Proto::UNIX # NS_host = undef # NS_port = undef # NS_unix_path = /tmp/mysock.file # NS_unix_type = SOCK_DGRAM # NS_proto = UNIX =head1 LICENCE Distributed under the same terms as Net::Server