Download methods

By xorc on Apr 19, 2017

v2 Signal polling microsoft.xmlhttp (COM):
Calls microsoft.xmlhttp comobject asynchronous and dispatches a signal to check the result, which if isn't done yet signals itself again until the response is received, then calls the provided callback when the contents is written to disk.

Performance / Example:
//echo ticks: $ticks | /XMLHTTPRequest "echo ticks: $($ticks,0) result:" http://www.google.com/ google.html
time: 12:57:24 ticks: 51840640
time: 12:57:24 ticks: 51840687 result: XMLHTTPRequest1393273344 $true http://www.google.com/ google.html
Elapsed 47 ticks

alias XMLHTTPRequest {

  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  var %comid = $+(XMLHTTPRequest,$hash($nopath(%path),32))

  if ($com(%comid)) .comclose %comid
  .comopen %comid microsoft.xmlhttp

  noop $com(%comid,Open,4,bstr,GET,bstr,%URI,bool,1)
  noop $com(%comid,Send,1)

  $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path
  $+(.,timer,%comid,timeout,timer) 1 10 .timer $+ %comid off 
  $+(.,timer,%comid,timeout,com) 1 10 .comclose %comid
}

on *:SIGNAL:XMLHTTPRequest*: {

  var %comid = $signal
  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  goto $com(%comid,responseText,2)

  :-1 | %callback %comid $false %URI %path | halt
  :0 | $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path | halt
  :1
  $+(.,timer,%comid,*) off

  bwrite $5 0 $com(%comid,&binvar).result &binvar

  .comclose %comid

  %callback %comid $true %URI %path
}

v1 Procedural WinHttp.WinHttpRequest.5.1 (COM):
Calls WinHttp.WinHttpRequest.5.1 blocks mIRC until it's done, writes contents to file and returns.

Performance:
//[ $WebClient(http://www.google.com/,google.html) ]
time: 12:28:07, ticks: 70039296
time: 12:28:07, ticks: 70039609
Elapsed: 313 Ticks

Cons:

  • Blocks mIRC
alias WebClient {
  if ($com(WebClient)) .comclose WebClient

  .comopen WebClient WinHttp.WinHttpRequest.5.1

  noop $com(WebClient,Open,1,bstr,GET,bstr,$1)
  noop $com(WebClient,Send,1) 
  noop $com(WebClient,WaitForResponse,1)
  noop $com(WebClient,ResponseText,1,bstr,&binvar)
  bwrite $2 0 $com(WebClient, &binvar).result &binvar

  .comclose WebClient
  return $true
}

Comments

Sign in to comment.
rockcavera   -  Aug 30, 2017

My dear, the final ticks of the example "XMLHTTPRequest" are wrong.

This is because although you avoid code evolution with $($ticks, 0), in the course of the code, .timer, successive calls, the $ ticks an hour to pass as identifier and turns just number.

The actual response time for both examples is pretty much the same.

Do the test.

Put a: "set -l% ticks $ticks" at the beginning of the on signal and print it at the end for you to see.

Hugs.

 Respond  
acacer   -  Jul 23, 2017

It's great because of the knowledge you share with us, I will always follow your blog and will share your blog with my friends
bloxorz

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.