mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
In the sockclose event $sockerr is set to 3 when the connection was established with ssl. Everything in the socket behaves as expected and identically to the socket without ssl. Even if there is a difference in low level behavior when handling ssl, I don't think $sockerr should be > 0 as no error has actually occurred. In both cases I receive a perfect copy of the file from the server.

Code:
//http | http -ssl

-http-
sockerr: 0
wsmsg: [0] Unknown Error
header size: 734
data size: 33366

-https-
sockerr: 3
wsmsg: [10101] Host disconnected
header size: 734
data size: 33370


Code:
alias http {
  if ($1 == -ssl) { var %ssl = 1 | tokenize 32 $2- }
  var %host = $iif($1,$1,www.google.com)
  var %sockname = $+(http,$ticks,$rand(1000,9999))
  hadd -m %sockname headerfile $+(%sockname,_header.txt)
  hadd %sockname datafile $+(%sockname,_data.html)
  sockopen $iif(%ssl,-e) %sockname %host $iif(%ssl,443,80)
}

on *:sockopen:http*:{
  var %a = sockwrite -n $sockname

  var %host = $sock($sockname).addr
  var %port = $sock($sockname).port
  var %method = GET 
  var %page = /

  %a %method %page HTTP/1.0
  %a Host: $+(%host,:,%port)
  %a Connection: close
  %a $crlf
}

on *:sockread:http*:{
  var %header

  if (!$hget($sockname,header)) {
    sockread %header
    while (%header != $null) {
      write $hget($sockname,headerfile) %header
      sockread %header
    }
    if ($sockbr) hadd $sockname header 1
  }
  if ($hget($sockname,header)) {
    sockread &read
    while ($sockbr) {
      bwrite $hget($sockname,datafile) -1 -1 &read
      sockread &read
    }
  }
}

on *:sockclose:http*:{
  echo -ag sockerr: $sockerr
  echo -ag wsmsg: $sock($sockname).wsmsg
  echo -ag header size: $file($hget($sockname,headerfile)).size
  echo -ag data size: $file($hget($sockname,datafile)).size
  
  .remove $hget($sockname,headerfile)
  .remove $hget($sockname,datafile)
  hfree $sockname
}

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
It might be the way google is closing the socket, not making sure their send queue is clear.

As this shows, there's still data in the recieve buffer when google closes the connection:
Code:
alias httptest {
  sockopen httptest google.com 80
  sockopen -e httptests google.com 443
}

on *:sockopen:httptest*:{
  if ($sockerr) {
    echo 04 -a [SockOpen Error] $sockname $+ : $v1 $sock($sockname).wserr $sock($sockname).wsmsg
  }
  else {
    echo 12 -a [SockOpen] $sockname
    var %a = sockwrite -n $sockname
    %a GET / HTTP/1.0
    %a Host: www.google.com
    %a Connection: close
    %a
  }
}
on *:SOCKWRITE:httptest*:{
  if ($sockerr) {
    echo 04 -a [SockWrite Error] $sockname $+ : $v1 $sock($sockname).wserr $sock($sockname).wsmsg
  }
}

on *:sockread:httptest*:{
  if ($sockerr) {
    echo 04 -a [SockOpen Error] $sockname $+ : $v1 $sock($sockname).wserr $sock($sockname).wsmsg
  }
  else {
    var %r
    sockread %r
    while ($sockbr) sockread -f %r
  }
}

on *:sockclose:httptest*:{
  if ($sockerr) {
    echo 04 -a [SockClose Error] $sockname $+ : $v1 $sock($sockname).wserr $sock($sockname).wsmsg 
  }
  else {
    echo 12 -a [SockClose] $sockname
  }
  echo 03 -a Bytes Send: $sock($sockname).sent - Bytes to send: $sock($sockname).sq
  echo 03 -a Bytes Rcvd: $sock($sockname).rcvd - Bytes to rcvd: $sock($sockname).rq
}

Last edited by FroggieDaFrog; 14/02/12 04:50 AM.

I am SReject
My Stuff
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
With your script if you use the host "www.google.com" (without the www. you are not receiving the full page text) both ssl/non ssl have .rq > 0. And only in ssl is $sockerr > 0. Additionally, this is not limited to google. It is any ssl connection.

If you echo the same information in my provided script, .rq is 0. (I have seen it larger than 0, but am unable to reproduce).

From mine:
Code:
sockerr: 0
wsmsg: [0] Unknown Error
header size: 734
data size: 33378
Bytes Send: 62 - Bytes to send: 0
Bytes Rcvd: 34114 - Bytes to rcvd: 0
sockerr: 3
wsmsg: [10101] Host disconnected
header size: 734
data size: 33442
Bytes Send: 63 - Bytes to send: 0
Bytes Rcvd: 34178 - Bytes to rcvd: 0


From yours:
Code:
[SockOpen] httptest
[SockClose] httptest
Bytes Send: 62 - Bytes to send: 0
Bytes Rcvd: 34081 - Bytes to rcvd: 9
[SockOpen] httptests
[SockClose Error] httptests: 3 10101 [10101] Host disconnected
Bytes Send: 63 - Bytes to send: 0
Bytes Rcvd: 34103 - Bytes to rcvd: 9

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Right you are about the host, but after changing it to what it should be, here's me results:
Code:
;http:
[SockOpen] httptest
[SockClose] httptest
Bytes Send: 59 - Bytes to send: 0
Bytes Rcvd: 34105 - Bytes to rcvd: 9

;https
[SockOpen] httptests
[SockClose Error] httptests: 3 10101 [10101] Host disconnected
Bytes Send: 59 - Bytes to send: 0
Bytes Rcvd: 33039 - Bytes to rcvd: 344


So I don't know what would be causing the error after all :S


I am SReject
My Stuff
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Using sockread -f solves the .rq issue in your script.

Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
I can reproduce this and I agree $sockerr shouldn't be set there, winsock reports that 10101 is a graceful shutdown in progress.
If you can read all the data in your on sockread event using the loop on $sockbr, if you read all the receive buffer using /sockread $sock($sockname).rq &a, mIRC will call on sockclose with $sockerr set to 3 before you can read everything inside on sockread, you are forced to use on sockclose to read everything.
The best for scripters would really be to have mIRC stops triggering on sockclose in this situation but rather triggers it later, when the socket is actually closed.
Handling this situation in a script is not hard but having it built in would make our life easier and would improve the design.

Code:
;/testsock
alias testsock {
  if (!$sslready) { echo -s * /testsock requires SSL | return }
  sockclose testsock
  if ($exists(testsock.txt)) .remove testsock.txt
  sockopen -e testsock dl.dropboxusercontent.com 443
}
on *:sockopen:testsock:{
  if ($sockerr) { echo -s * /testsock sockerr on sockopen $sock($sockname).wserr $sock($sockname).wsmsg | return }
  sockwrite -n $sockname GET /u/4249275/Bomberman/bomber.mrc HTTP/1.1
  sockwrite -n $sockname Host: dl.dropboxusercontent.com
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname 
  sockmark $sockname $false
}
on *:sockread:testsock:{
  if (!$sockerr) {
    if ($sock($sockname).mark) {
      echo -a reading $sock($sockname).rq bytes
      sockread $sock($sockname).rq &a
    }
    else {
      var %a
      sockread %a
      if (%a == $null) sockmark $sockname 1
      elseif ($sock($sockname).mark == $false) {
        if (*200 OK* !iswm %a) {
          echo -s * /testsock cannot find the file on the server
          sockclose testsock
        }
        sockmark $sockname 0
      }
    }
  }
  else {
    echo -s * /testsock sockerr on sockread $sock($sockname).wserr $sock($sockname).wsmsg
  }
}

on *:sockclose:testsock:{
  if ($sockerr) { echo -s * /testsock sockerr on sockclose $sock($sockname).wserr $sock($sockname).wsmsg -- $!sock().rq = $sock($sockname).rq | return }
  echo -a sockclose $!sock().rq : $sock($sockname).rq
  if ($exists(testsock.txt)) .remove testsock.txt
}

Last edited by Wims; 07/08/14 05:19 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,421
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,421
There are a number of combining factors that are causing an error to be set here: the way mIRC handles OpenSSLs socket read/write/close/error events, how these are passed to socket routines to be processed, the fact that SSL events and non-SSL events trigger on SOCK* events slightly differently (which cannot be changed as this would break existing scripts), and so on.

In order to prevent this error from being set, quite a few changes to both SSL and non-SSL routines are required.

Normally, I would prefer not to make complicated changes to stable code to resolve a small issue that has been around for so long. However, I am currently adding support for CAP STARTTLS, which requires quite a few changes anyway, so I have gone ahead and implemented a fix for this issue.

The next public beta will require extensive testing to ensure backward compatibility with existing socket scripts.

Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
Great, thanks!


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard