Net-SSLeay-1.20 > Net::SSLeay::Handle
Net-SSLeay-1.20
Other versions:
Net-SSLeay-1.36

名前

Net::SSLeay::Handle - Perl module that lets SSL (HTTPS) sockets be handled as standard file handles.

Net::SSLeay::Handle - SSL (HTTPS)ソケットを標準のファイルハンドルとして 扱わせるPerlモジュール

概要

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL;                                                       
  

説明

Net::SSLeay::Handle allows you to request and receive HTTPS web pages using "old-fashion" file handles as in:

Net::SSLeay::HandleはHTTPS webページを"昔ながらの"ファイルハンドルを 使って以下のように、リクエストしたり、受け取ることを可能にします:

    print SSL "GET / HTTP/1.0\r\n";

and

そして

    print while (<SSL>);

If you export the shutdown routine, then the only extra code that you need to add to your program is the tie function as in:

shutdownルーチンをエクスポートすると、あなたのプログラムに追加する 必要がある特別なコードは、以下のようなtie関数だけになります:

    my $socket;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", host, $port);
        $socket = \*S2;
    else {
        $socket = Net::SSLeay::Handle->make_socket(host, $port);
    }
    print $socket $request_headers;
    ... 

既存のソケットを利用する

One of the motivations for writing this module was to avoid duplicating socket creation code (which is mostly error handling). The calls to tie() above where it is passed a $host and $port is provided for convenience testing. If you already have a socket connected to the right host and port, S1, then you can do something like:

このモジュールを作った動機の一つは、ソケットを作るコードが重複する ことを避けることでした(そのほとんどはエラーの取り扱いになります)。 上記の$hostと$portが渡されるところでtie()を呼び出すことは、 便宜上、テストのために提供されています。正しいホストとポートに 接続されたソケットS1を既に持っているのであれば、以下のように することができます:

    my $socket \*S1;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", $socket);
        $socket = \*S2;
    }
    my $last_sel = select($socket); $| = 1; select($last_sel);
    print $socket $request_headers;
    ... 

Note: As far as I know you must be careful with the globs in the tie() function. The first parameter must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob (as in the example above)

注意: 私が知る限り、tie()関数ではグロブの取り扱いには注意しなければ なりません。最初のパラメータはグロブ(*SOMETHING)でなければなりません。 そして最後のパラメータはグロブへのリファレンス(\*SOMETHING_ELSE)あるいは (上記の例のように)グロブへのリファレンスが代入されたスカラーでなければ なりません。

Also, the two globs must be different. When I tried to use the same glob, I got a core dump.

また2つのグロブは違うものでなければなりません。私が同じグロブを使おうと したときには、コアダンプになりました。

EXPORT

None by default.

デフォルトでは何もありません。

You can export the shutdown() function.

shutodown()関数をエクスポートすることができます。

It is suggested that you do export shutdown() or use the fully qualified Net::SSLeay::Handle::shutdown() function to shutdown SSL sockets. It should be smart enough to distinguish between SSL and non-SSL sockets and do the right thing.

SSLソケットをシャットダウンするためには、shutdown()をエスクポートするか、 完全に修飾されたNet::SSLeay::Handle::shutdown()関数を使うことを提案します。 SSLと非SSLソケットを区別し、正しいことを行うのに十分スマートです。

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL; 

TODO

Better error handling. Callback routine?

よりよいエラーの取り扱い、コールバックルーチン?

CAVEATS

Tying to a file handle is a little tricky (for me at least).

ファイルハンドルを使おうとすることは少しトリッキーです(少なくとも私にとっては)。

The first parameter to tie() must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob ($s = \*SOMETHING_ELSE). Also, the two globs must be different. When I tried to use the same glob, I got a core dump.

tie()への最初のパラメータはグロブ(*SOMETHING)で、最後のパラメータは グロブへのリファレンス(\*SOMETHING_ELSE)か、グロブへのリファレンスが 代入されたスカラー($s = \*SOMETHING_ELSE)でなければなりません。 また2つのグロブは違うものでなければなりません。私が同じグロブを使おうと したときには、コアダンプになりました。

I was able to associate attributes to globs created by this module (like *SSL above) by making a hash of hashes keyed by the file head1.

ファイルヘッド1によりキーが付けられたハッシュのハッシュを作ることにより、 このモジュールにより作成されたグロブに属性を関連付けることができました (上記の*SSLのように)。

Support for old perls may not be 100%. If in trouble try 5.6.0 or newer.

古いperlのサポートは100%ではないかもしれません。障害時には5.6.0以上を お試しください。

CHANGES

Please see Net-SSLeay-Handle-0.50/Changes file.

Net-SSLeay-Handle-0.50/Changesファイルをご覧ください。

KNOWN BUGS

If you let this module construct sockets for you with Perl versions below v.5.6 then there is a slight memory leak. Other upgrade your Perl, or create the sockets yourself. The leak was created to let these older versions of Perl access more than one Handle at a time.

Perlバージョンv5.6以前で、このモジュールにあなた用のソケットを作る よう命令すると、少しメモリリークを起こします。Perlをアップグレードするか、 あなた自身でソケットを作成してください。そのリークは、これらの古い バージョンのPerlに同時に1つ以上のハンドルにアクセスさせるために 作られます。

作者

Jim Bowlin jbowlin@linklint.org

SEE ALSO

Net::SSLeay, perl(1), http://openssl.org/