on *:SOCKREAD:sockname:{
;loop back position
:loop
;Check for sockerr
if ($sockerr) {
;if sockerror occured, check if hashtable is opened
if ($hget($sockname)) {
;if hashtable is opened, close it
hfree $sockname
}
;if sockerr, stop processing
return
}
;read data from socket to &tmp1
sockread &tmp1
;if no data was read, stop processing
if (!$sockbr) { return }
;retrive data, if present, from the hashtable and set it to &tmp2
var %a = $hget($sockname,1,&tmp2)
;append the data that was read from the socket to the end of the stored data
bcopy -c &tmp2 $bvar(&tmp2,0) &tmp1 1 -1
;store &tmp2(old data + fresh data from socket)
hadd -mb $sockname 1 &tmp2
;loop back
goto loop
}
on *:SOCKWRITE:sockname:{
;check for socket errors
if ($sockerr) {
;if a sockerror occured, check to see if the hashtable is opened
if ($hget($sockname)) {
;free the hashtable if it's opened
hfree $sockname
}
;if a sockerr occured, stop processing
}
}
on *:sockclose:sockname:{
;check for socket errors
if ($sockerr) {
;if a sockerror occured, check to see if the hashtable is opened
if ($hget($sockname)) {
;free the hashtable if it's opened
hfree $sockname
}
;if a sockerr occured, stop processing
}
;check to see if any data was stored.
if ($hashtable($sockname)) {
;retrive data from the hashtable, and clear the hashtable
var %a = $hget($sockname,1,&tmp)
hfree $sockname
;replace all carriage-return+linefeeds with char(124) "|" (this also stops you from having multiple pipes side be side. IE: || )
var %data = $regsubex($bvar(&tmp,1,$bvar(&tmp,0)).text,/(?:\s+?\r\n\s+?)+/g,$chr(124))
;echo data out
echo -a %data
}
}