Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.7 KiB

  1. #
  2. # TEST-ASYNC.PL
  3. # Test Win32::Internet's Asynchronous Operations
  4. # by Aldo Calpini <[email protected]>
  5. #
  6. # WARNING: this code is most likely to fail with almost-random errors
  7. # I don't know what is wrong here, any hint will be greatly
  8. # appreciated!
  9. use Win32::Internet;
  10. $params{'flags'} = INTERNET_FLAG_ASYNC;
  11. $params{'opentype'} = INTERNET_OPEN_TYPE_DIRECT;
  12. $I = new Win32::Internet(\%params);
  13. # print "Error: ", $I->Error(), "\n";
  14. print "I.handle=", $I->{'handle'}, "\n";
  15. $return = $I->SetStatusCallback();
  16. print "SetStatusCallback=$return";
  17. print "ERROR" if $return eq undef;
  18. print "\n";
  19. $buffer = $I->QueryOption(INTERNET_OPTION_READ_BUFFER_SIZE);
  20. print "Buffer=$buffer\n";
  21. $host = "ftp.activeware.com";
  22. $user = "anonymous";
  23. $pass = "dada\@divinf.it";
  24. print "Doing FTP()...\n";
  25. $handle2 = $I->FTP($FTP, $host, $user, $pass, 21, 1);
  26. print "Returned from FTP()...\n";
  27. ($n, $t) = $I->Error();
  28. if($n == 997) {
  29. print "Going asynchronous...\n";
  30. ($status, $info) = $I->GetStatusCallback(1);
  31. while($status != 100 and $status != 70) {
  32. if($oldstatus != $status) {
  33. if($status == 60) {
  34. $FTP->{'handle'} = $info;
  35. } elsif($status == 10) {
  36. print "resolving name... \n";
  37. } elsif($status == 11) {
  38. print "name resolved... \n";
  39. } elsif($status == 20) {
  40. print "connecting... \n";
  41. } elsif($status == 21) {
  42. print "connected... \n";
  43. } elsif($status == 30) {
  44. print "sending... \n";
  45. } elsif($status == 31) {
  46. print "$info bytes sent. \n";
  47. } elsif($status == 40) {
  48. print "receiving... \n";
  49. } elsif($status == 41) {
  50. print "$info bytes received. \n";
  51. } else {
  52. print "status=$status\n";
  53. }
  54. }
  55. $oldstatus = $status;
  56. ($status, $info) = $I->GetStatusCallback(1);
  57. }
  58. } else {
  59. print "Error=", $I->Error(), "\n";
  60. }
  61. print "FTP.handle=", $FTP->{'handle'}, "\n";
  62. print "STATUS(after FTP)=", $I->GetStatusCallback(1), "\n";
  63. # "/pub/microsoft/sdk/activex13.exe",
  64. print "Doing Get()...\n";
  65. $file = "/Perl-Win32/perl5.001m/currentBuild/110-i86.zip";
  66. $FTP->Get($file, "110-i86.zip", 1, 0, 2);
  67. print "Returned from Get()...\n";
  68. ($n, $t) = $I->Error();
  69. if($n == 997) {
  70. print "Going asynchronous...\n";
  71. $bytes = 0;
  72. $oldstatus = 0;
  73. ($status, $info) = $I->GetStatusCallback(2);
  74. while($status != 100 and $status != 70) {
  75. # print "status=$status info=$info\n";
  76. # if($oldstatus!=$status) {
  77. if($status == 10) {
  78. print "resolving name... \n";
  79. } elsif($status == 11) {
  80. print "name resolved... \n";
  81. } elsif($status == 20) {
  82. print "connecting... \n";
  83. } elsif($status == 21) {
  84. print "connected... \n";
  85. #} elsif($status == 30) {
  86. # print "sending... \n";
  87. } elsif($status == 31) {
  88. print "$info bytes sent. \n";
  89. #} elsif($status == 40) {
  90. # print "receiving... \n";
  91. } elsif($status == 41) {
  92. $bytes = $bytes+$info;
  93. print "$bytes bytes received. \n";
  94. #} else {
  95. # print "status=$status\n";
  96. }
  97. # }
  98. $oldstatus = $status;
  99. undef $status, $info;
  100. ($status, $info) = $I->GetStatusCallback(2);
  101. }
  102. } else {
  103. print "Error=[$n] $t\n";
  104. }
  105. print "\n";
  106. ($status, $info) = $I->GetStatusCallback(2);
  107. print "STATUS(after Get)=$status\n";
  108. print "Error=", $I->Error(), "\n";
  109. exit(0);