免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2475 | 回复: 5
打印 上一主题 下一主题

菜鸟使用AnyEvent::HTTP的问题,请大家看看 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-12 11:06 |只看该作者 |倒序浏览
以前用过LWP系列的模块,现在试了试AnyEvent::HTTP这个模块。下面是cpan上一个简单的小例子,但我执行完后,没有任何输出。请大家看看可能是什么原因?谢谢
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use AnyEvent::HTTP;
  5. http_request
  6.     GET => "http://www.163.com",
  7.     sub {
  8.         my ($body, $hdr) = @_;

  9.         if ($hdr->{Status} =~ /^2/) {
  10.             print "$hdr->{Status}, everything should be ok";
  11.         } else {
  12.             print "error, $hdr->{Status} $hdr->{Reason}\n";
  13.         }   
  14.     };
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-04-12 13:53 |只看该作者
define callback

论坛徽章:
0
3 [报告]
发表于 2011-04-12 14:26 |只看该作者
回复 2# albertd


   能否详细点,是cb => sub{ };这样吗?

论坛徽章:
0
4 [报告]
发表于 2011-04-20 18:32 |只看该作者
重新看了下AnyEvent,需要些条件变量
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use AnyEvent::HTTP;
  5. my $cv = AnyEvent->condvar;
  6. http_request
  7.     GET => "http://www.163.com",
  8.     sub {
  9.         my ($body, $hdr) = @_;
  10.         $cv->send;

  11.         if ($hdr->{Status} =~ /^2/) {
  12.             print "$hdr->{Status}, everything should be ok";
  13.         } else {
  14.             print "error, $hdr->{Status} $hdr->{Reason}\n";
  15.         }   
  16.     };
  17. $cv->recv;
复制代码
这样就可以了

论坛徽章:
1
辰龙
日期:2014-05-15 19:37:15
5 [报告]
发表于 2011-04-21 11:19 |只看该作者
对,轮子要转起来,才会跑,不然只告诉 anyevent 有这么个东西,还是不会跑的

论坛徽章:
0
6 [报告]
发表于 2011-04-23 08:21 |只看该作者
***
*** The EV module is recommended for even better performance, unless you
*** have to use one of the other adaptors (Event, Glib, Tk, etc.).
*** The Async::Interrupt module is highly recommended to efficiently avoid
*** race conditions in/with other event loops.
***
*** This module does not have ANY dependencies, even if it might look
*** otherwise. If you are building a distribution package or have
*** difficulties installing this package due to dependencies, report this
*** to the packager as a bug.
***
*** This module is guaranteed to stay 100% pure-perl, full-featured
*** and performant, even without any of the optional modules.
***

这个模块是不是有性能优势?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP