Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2 » StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/SocketLib

StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/SocketLib

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2
Filename: StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/SocketLib
Read OK:
File size: 4675 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM >SocketLib
   20REM LEN Justin Fletcher
   30REM Version : 1.11 (15 Jun 1997)
   40REM Tested with Acorn !Internet and FreeNet suites
   50REM Massively bug-fixed by Dave Thomas
   60REM Non-blocking connect and DNS query added by Reuben Thomas
   70ERROR &803,"Do not run the Socket Library"
   80:
   90REM PROCinitsockets : Initialise the sockets library
  100DEFPROCinitsockets
  110SYS "XOS_SWINumberFromString",,"Socket_Creat" TO;flags%
  120IF (flags% AND1) THENreply=FNerrorbox("SocketLib","This application requires an internet suite to be installed.",%10):END
  130*RMEnsure InetServices 1.07 RMLoad System:Modules.Network.IServices
  140*RMEnsure InetServices 1.07 Set NoIServicesModule True
  150IF FNsystemvar("NoIServicesModule")="True" THENOSCLI("Unset NoIServicesModule"):reply=FNerrorbox("SocketLib","This application requires a later version of the IServices module - this can be obtained with JFShared 2.42.",%10):END
  160REM Initialise error stuff
  170sockerr%=&805
  180REM Handles point to the descriptor blocks which give us details
  190REM about the sockets
  200DIM sock%(256),sockaddr% 16,socktemp% 256
  210sock%()=-1
  220REM Socket blocks :
  230REM  !0  = socket handle
  240REM  !4  = Buffered address
  250REM  !8  = Size of data in buffer
  260REM  !C  = flags :
  270REM         b0 = Listening (0 = Speaking, 1 = Listening)
  280REM         b1 = Buffered
  290REM         b2 = Non-blocking connect
  300REM Total size &10
  310socksize%=&10
  320REM Initialise buffered stuff
  330sockbuflen%=1024*2:REM 2k should be enough for most things
  340sockline%=FNclaim(sockbuflen%):REM For copying the string into
  350REM Read the number of handles available
  360SYS "Socket_Gettsize" TO socktsize%
  370REM Initialise constants
  380FIONREAD=&4004667F
  390FIONBIO=&8004667E
  400SO_SNDBUF=&1001
  410SO_RCVBUF=&1002
  420AF_INET=2
  430REM Multitasking chain of handles used
  440mtchain%=0
  450ENDPROC
  460:
  470REM FNsocket_findhandle : Find a socket handle and claim space
  480DEFFNsocket_findhandle
  490LOCALsock%,o%
  500sock%=-1:REPEAT:sock%+=1:UNTIL sock%(sock%)=-1 OR sock%=256
  510IF sock%=256 THEN=-1
  520sock%(sock%)=FNclaim(socksize%)
  530IF sock%(sock%)<0 THEN=-1
  540FORo%=0TOsocksize%-4 STEP4:sock%(sock%)!o%=0:NEXT
  550=sock%
  560:
  570REM FNsocket_createinet : Make a socket for internet use
  580DEFFNsocket_createinet
  590LOCALsock%:sock%=FNsocket_findhandle
  600IF sock%=-1 THEN=-1
  610REM PF_INET, SOCK_STREAM, and default protocol
  620SYS "Socket_Creat",2,1,0 TO sock%(sock%)!0
  630IF sock%(sock%)!0=-1 THEN PROCrelease(sock%(sock%)):=-1
  640=sock%
  650:
  660DEFPROCsocket_check(sock%,r$)
  670IF sock%<0 ORsock%>256 THENERROR sockerr%,r$+": Socket out of range"
  680IF sock%(sock%)<0 THENERROR sockerr%,r$+": Socket has been closed"
  690ENDPROC
  700:
  710REM PROCsocket_listen : Listen on a particular socket
  720DEFPROCsocket_listen(sock%,ip%,port%)
  730LOCALflags%,r0:port%=port% AND &FFFF
  740PROCsocket_check(sock%,"Listen")
  750sockaddr%!0=AF_INET OR((port% DIV256)<<16) OR((port% MOD256)<<24)
  760sockaddr%!4=ip%:REM In reverse order
  770sockaddr%!8=0:sockaddr%!12=0:REM Reserved
  780SYS "XSocket_Bind",sock%(sock%)!0,sockaddr%,16 TOr0;flags%
  790IF (flags% AND1)=1 THENERROR sockerr%,"Bind: "+FNstring0(r0+4)
  800REM Mark as a non-blocking socket
  810!socktemp%=-1:SYS "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
  820REM Make it listen
  830SYS "XSocket_Listen",sock%(sock%)!0,5 :REM 5 is the backlog
  840REM Mark as listening (ie we're answering)
  850sock%(sock%)!&C=(sock%(sock%)!&C AND NOT 1) OR 1
  860ENDPROC
  870:
  880REM FNsocket_findlisten : Listen on a socket, jumping on if error
  890DEFFNsocket_findlisten(sock%,ip%,port%,limit%)
  900LOCALflags%,r0:port%=port% AND &FFFF
  910PROCsocket_check(sock%,"FindListen")
  920REPEAT
  930 sockaddr%!0=AF_INET OR((port% DIV256)<<16) OR((port% MOD256)<<24)
  940 sockaddr%!4=ip%:REM In reverse order
  950 sockaddr%!8=0:sockaddr%!12=0:REM Reserved
  960 SYS "XSocket_Bind",sock%(sock%)!0,sockaddr%,16 TOr0;flags%
  970 IF (flags% AND1)=1 THENport%+=1:limit%-=1
  980UNTIL (flags% AND1)=0 OR limit%<0
  990IF limit%<0 THEN=-1
 1000REM Mark as a non-blocking socket
 1010!socktemp%=-1:SYS "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
 1020REM Make it listen
 1030SYS "XSocket_Listen",sock%(sock%)!0,5 :REM 5 is the backlog
 1040REM Mark as listening (ie we're answering)
 1050sock%(sock%)!&C=(sock%(sock%)!&C AND NOT 1) OR 1
 1060=port%
 1070:
 1080REM FNsocket_connect : Connect to a remote host
 1090DEFFNsocket_connect(sock%,ip%,port%)
 1100LOCALflags%,r0:port%=port%AND&FFFF
 1110PROCsocket_check(sock%,"Connect")
 1120REM AF_INET and port number
 1130sockaddr%!0=2 OR ((port% DIV256)<<16) OR ((port% MOD256)<<24)
 1140sockaddr%!4=ip%:REM In reverse order
 1150sockaddr%!8=0:sockaddr%!12=0:REM Reserved
 1160SYS "XSocket_Connect",sock%(sock%)!0,sockaddr%,16 TOr0;flags%
 1170IF (flags% AND1)=1 THEN=FALSE
 1180REM Mark as a non-blocking socket
 1190!socktemp%=-1:SYS "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
 1200REM Mark as talking (ie we're doing the connecting)
 1210sock%(sock%)!&C=(sock%(sock%)!&C AND NOT 1)
 1220=TRUE
 1230:
 1240REM FNsocket_noblockconnect : Connect without blocking
 1250REM Returns FALSE if couldn't connect, TRUE if it did
 1260REM and -TRUE if it is currently trying.
 1270DEFFNsocket_noblockconnect(sock%,ip%,port%)
 1280LOCALflags%,r0,res%:port%=port%AND&FFFF
 1290PROCsocket_check(sock%,"Connect")
 1300REM Mark as a non-blocking socket
 1310!socktemp%=-1:SYS "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
 1320REM AF_INET and port number
 1330sockaddr%!0=2 OR ((port% DIV256)<<16) OR ((port% MOD256)<<24)
 1340sockaddr%!4=ip%:REM In reverse order
 1350sockaddr%!8=0:sockaddr%!12=0:REM Reserved
 1360SYS "XSocket_Connect",sock%(sock%)!0,sockaddr%,16 TOr0;flags%
 1370IF (flags% AND1)=1 THEN
 1380 REM Check for error EINPROGRESS (36)
 1390 IF !r0=36 THENres%=1 ELSE=FALSE
 1400ELSE
 1410 REM Otherwise it's connected already
 1420 res%=TRUE
 1430ENDIF
 1440REM Mark as talking, and we're non-blocking
 1450sock%(sock%)!&C=(sock%(sock%)!&C AND NOT 1) OR 4
 1460=res%
 1470:
 1480REM FNsocket_accept : Accept a connection
 1490DEFFNsocket_accept(main%)
 1500PROCsocket_check(main%,"Accept")
 1510LOCAL skt%,sock%,O:sock%=FNsocket_findhandle
 1520IF sock%=-1 THEN=-1
 1530!socktemp%=16
 1540SYS "XSocket_Accept",sock%(main%)!0,sockaddr%,socktemp% TO skt%;flags%
 1550IF (flags% AND 1)=1 OR skt%=-1 THENPROCrelease(sock%(sock%)):=-1
 1560sock%(sock%)!0=skt%
 1570REM Copy the socket block
 1580FORO=4TO socksize%-4 STEP 4:sock%(sock%)!O=sock%(main%)!O:NEXT
 1590REM If it is a buffered socket then claim some memory for it
 1600IF ((sock%(main%)!&C) AND 2)=2 THEN
 1610 sock%(sock%)!4=FNclaim(sockbuflen%)
 1620 IF sock%(sock%)!4<0 THEN
 1630  REM Not enough memory to claim
 1640  PROCrelease(sock%(sock%))
 1650  =-1
 1660 ENDIF
 1670 sock%(sock%)!8=0:REM No bytes in buffer
 1680ENDIF
 1690=sock%
 1700:
 1710REM ******** NOTE ******
 1720REM Two calls not included in the SH manual or distributed yet
 1730REM PROCsocket_recvbuffer : Sets the size of the receive buffer
 1740DEFPROCsocket_recvbuffer(sock%,!socktemp%)
 1750PROCsocket_check(sock%,"RecvBuffer")
 1760SYS "Socket_Setsockopt",sock%(sock%)!0,&FFFF,SO_RCVBUF,socktemp%,4
 1770ENDPROC
 1780:
 1790REM PROCsocket_sendbuffer : Sets the size of the send buffer
 1800DEFPROCsocket_sendbuffer(sock%,!socktemp%)
 1810PROCsocket_check(sock%,"RecvBuffer")
 1820SYS "Socket_Setsockopt",sock%(sock%)!0,&FFFF,SO_SNDBUF,socktemp%,4
 1830ENDPROC
 1840:
 1850REM PROCsocket_makebuffered : Ensures that a socket is buffered
 1860DEFPROCsocket_makebuffered(sock%)
 1870PROCsocket_check(sock%,"MakeBuffered")
 1880IF ((sock%(sock%)!&C) AND 2)=2 THENENDPROC
 1890sock%(sock%)!4=FNclaim(sockbuflen%)
 1900IF sock%(sock%)!4<0 THENERROR sockerr%,"MakeBuffered: Could not claim enough memory"
 1910sock%(sock%)!8=0:REM No bytes in buffer
 1920sock%(sock%)!&C=(sock%(sock%)!&C) OR 2
 1930ENDPROC
 1940:
 1950REM PROCsocket_makelinger : Socket will (not) linger on close
 1960DEFPROCsocket_makelinger(sock%,time%)
 1970PROCsocket_check(sock%,"MakeLinger")
 1980socktemp%!0=1+(time%=0):socktemp%!4=time%
 1990SYS "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&80,socktemp%,8
 2000ENDPROC
 2010:
 2020REM PROCsocket_makereusable : Socket can be reused when closed
 2030DEFPROCsocket_makereusable(sock%,flag%)
 2040PROCsocket_check(sock%,"MakeReusable")
 2050socktemp%!0=-(flag%<>0)
 2060SYS "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&4,socktemp%,4
 2070SYS "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&200,socktemp%,4
 2080ENDPROC
 2090:
 2100REM PROCclosesockets : Kill all active sockets and closedown
 2110DEFPROCclosesockets
 2120LOCAL I%,s%
 2130FORI%=0TO256:s%=I%:PROCsocket_close(s%):NEXT
 2140PROCrelease(sockline%)
 2150WHILE mtchain%<>0:PROCinet_killmtquery(mtchain%):ENDWHILE
 2160ENDPROC
 2170:
 2180REM PROCsocket_close : Close a socket down
 2190DEFPROCsocket_close(RETURN sock%)
 2200IF sock%>=0 AND sock%<=256 THEN
 2210 IF sock%(sock%)>-1 THEN
 2220  SYS "XSocket_Shutdown",sock%(sock%)!0,2
 2230  SYS "XSocket_Close",sock%(sock%)!0
 2240  IF ((sock%(sock%)!&C) AND 2)=2 THENPROCrelease(sock%(sock%)!&4)
 2250  PROCrelease(sock%(sock%))
 2260 ENDIF
 2270ENDIF
 2280sock%=-1
 2290ENDPROC
 2300:
 2310REM FNsocket_inbuffer : Read amount of data in input buffer
 2320DEFFNsocket_inbuffer(sock%)
 2330PROCsocket_check(sock%,"InBuffer")
 2340SYS "XSocket_Ioctl",sock%(sock%)!0,FIONREAD,socktemp%
 2350=!socktemp%
 2360:
 2370REM FNsocket_eof : Return TRUE if the other end has closed
 2380DEFFNsocket_eof(sock%)
 2390PROCsocket_check(sock%,"Eof")
 2400LOCAL ok,f%:ok=FNsocket_ready(sock%,TRUE)
 2410IF ok<>0 THEN
 2420 REM MSG_PEEK + MSG_DONTWAIT
 2430 SYS "XSocket_Recv",sock%(sock%)!0,socktemp%,1,&2+&80 TO ok;f%
 2440 ok=(ok=0) OR (f% AND1)=1
 2450ENDIF
 2460=ok
 2470:
 2480REM FNsocket_ready : Check whether a socket is usable
 2490DEFFNsocket_ready(sock%,read%)
 2500PROCsocket_check(sock%,"Ready")
 2510LOCAL I,fd%,b%,ok%,r%,w%:fd%=sock%(sock%)!0:b%=socktemp%
 2520FOR I=0 TO ((socktsize%/8+3) AND NOT3)-1 STEP 4:socktemp%!I=0:NEXT
 2530WHILE fd%>=32:b%+=4:fd%-=32:ENDWHILE:!b%=!b% OR (1<<fd%)
 2540b%=socktemp%+I:!b%=0:b%!4=0:REM immediate return
 2550IF read% THENr%=socktemp% ELSEw%=socktemp%
 2560SYS "Socket_Select",socktsize%,r%,w%,0,b% TO ok%
 2570=ok%
 2580:
 2590REM FNsocket_connected : Check if we are connected yet
 2600REM TRUE if we are, FALSE if working on it
 2610REM error, otherwise
 2620DEFFNsocket_connected(sock%)
 2630LOCAL ok,f%
 2640REM MSG_PEEK + MSG_DONTWAIT
 2650SYS "XSocket_Recv",sock%(sock%)!0,socktemp%,1,&2+&80 TO ok;f%
 2660IF (f% AND1) THEN
 2670 ok=!ok:IF ok=35 THENok=TRUE ELSEIF ok=36 OR ok=57 THENok=FALSE
 2680ELSE
 2690 ok=TRUE
 2700ENDIF
 2710=ok
 2720:
 2730REM FNsocket_readdata : Read data into buffer
 2740DEFFNsocket_readdata(sock%,RETURN start%)
 2750LOCAL read%:read%=0
 2760PROCsocket_check(sock%,"ReadData")
 2770REM Read data from socket to our buffer if buffered, else to users
 2780IF ((sock%(sock%)!&C) AND 2)=2 THENstart%=sock%(sock%)!4
 2790IF start%<&8000 THENERROR sockerr%,"ReadData: Stupid address for socket_readdata ("+STR$~start%+"), flags = "+STR$(sock%(sock%)!&C)
 2800IF FNsocket_inbuffer(sock%)>0 THEN
 2810 SYS "Socket_Read",sock%(sock%)!0,start%,sockbuflen% TO read%
 2820ENDIF
 2830=read%
 2840:
 2850REM FNsocket_readline : Read a line into a temporary buffer
 2860REM Line will be in a temporary buffer, terminated by 0
 2870REM -1 will be returned if no complete line has been received
 2880DEFFNsocket_readline(sock%,RETURN start%)
 2890LOCAL buf%,ofs%,I%,O%,read%
 2900PROCsocket_check(sock%,"ReadLine")
 2910IF (sock%(sock%)!&C AND 2)=0 THENERROR sockerr%,"ReadLine: Non-buffered socket_readline attempted"
 2920start%=-1
 2930REM Read data from socket to our buffer
 2940buf%=sock%(sock%)!4:ofs%=sock%(sock%)!8
 2950IF FNsocket_inbuffer(sock%)>0 THEN
 2960 IF buf%<&8000 THENERROR sockerr%,"ReadLine: Stupid address for socket_readline ("+STR$~start%+")"
 2970 SYS "Socket_Read",sock%(sock%)!0,buf%+ofs%,sockbuflen%-ofs% TO read%
 2980 IF read%<1 THENERROR sockerr%,"ReadLine: Didn't read anything ? "+STR$read%
 2990 ofs%=ofs%+read%
 3000ENDIF
 3010IF ofs%=0 THEN=-1
 3020FOR I%=0TO ofs%-1
 3030 IF buf%?I%=0 THENbuf%?I%=13
 3040 IF buf%?I%=10 OR buf%?I%=13 THEN
 3050  REM Copy line to buffer and terminate
 3060  FORO%=0TOI%:sockline%?O%=buf%?O%:NEXT
 3070  sockline%?I%=0
 3080  REM Copy remainder of buffer to start of buffer
 3090  FORO%=I%+1 TO ofs%-1:buf%?(O%-I%-1)=buf%?O%:NEXT
 3100  ofs%-=I%+1:sock%(sock%)!8=ofs%
 3110  REM Return with buffer and length
 3120  start%=sockline%:=I%+1
 3130 ENDIF
 3140NEXT
 3150sock%(sock%)!8=ofs%
 3160=-1
 3170:
 3180REM PROCsocket_sendline : Send a string to a socket
 3190DEFPROCsocket_sendline(sock%,m$)
 3200LOCAL r0,flags%
 3210PROCsocket_check(sock%,"SendLine")
 3220$(socktemp%)=m$+CHR$10
 3230SYS "XSocket_Write",sock%(sock%)!0,socktemp%,LEN(m$)+1 TOr0;flags%
 3240REM IF (flags% AND 1)=1 THENERROR sockerr%,"Write: "+FNstring0(r0+4)
 3250IF r0<>LEN(m$)+1 THENERROR sockerr%,"Could not send all data"
 3260ENDPROC
 3270:
 3280REM PROCsocket_senddata : Send data to a socket
 3290DEFPROCsocket_senddata(sock%,b%,len%)
 3300LOCAL r0,flags%
 3310PROCsocket_check(sock%,"SendData")
 3320SYS "XSocket_Write",sock%(sock%)!0,b%,len% TOr0;flags%
 3330REM IF (flags% AND 1)=1 THENERROR sockerr%,"Write: "+FNstring0(r0+4)
 3340ENDPROC
 3350:
 3360REM FNsocket_getpeername : Read the name of the other end
 3370DEFFNsocket_getpeername(sock%)
 3380LOCAL r0,r1
 3390PROCsocket_check(sock%,"GetPeerName")
 3400!socktemp%=16
 3410SYS "Socket_Getpeername",sock%(sock%)!0,sockaddr%,socktemp%
 3420REM "XInternet_GetHostByAddr"
 3430SYS &66001,0,sockaddr%+4,4,AF_INET TO ,r1;flags%
 3440IF (flags% AND1)=0 AND r1<>0 THEN=FNstring0(!r1)
 3450=STR$(sockaddr%?4)+"."+STR$(sockaddr%?5)+"."+STR$(sockaddr%?6)+"."+STR$(sockaddr%?7)
 3460:
 3470REM **************** Host and service specific ****************
 3480:
 3490REM FNinet_getservbyname : Read the port from service name
 3500DEFFNinet_getservbyname(name$,proto$)
 3510LOCAL servent%,port%
 3520IF VAL(name$)<>0 THEN=VAL(name$)
 3530SYS "Internet_GetServiceByName",name$,proto$ TO ,servent%
 3540IF servent%=0 THENport%=0 ELSEport%=servent%!8
 3550=port%
 3560:
 3570REM FNinet_getservbyport : Read the service name from port
 3580DEFFNinet_getservbyport(port%,proto$)
 3590LOCAL servent%,s$:port%=port%AND&FFFF
 3600SYS "Internet_GetServiceByPort",port%,proto$ TO ,servent%
 3610IF servent%=0 THENs$=STR$port% ELSEs$=FNstring0(!servent%)
 3620=s$
 3630:
 3640REM FNinet_gethostbyname : Return address of named host
 3650DEFFNinet_gethostbyname(host$)
 3660LOCAL ptr%,flags%
 3670REM "XInternet_GetHostByName"
 3680SYS &66000,0,host$ TO,ptr%;flags%
 3690IF ptr%=0 OR (flags% AND 1)=1 THEN=0
 3700=!!(ptr%!16):REM Yes, that is right, honest ;-)
 3710:
 3720REM FNinet_gethostbyaddr : Return name of host with given address
 3730DEFFNinet_gethostbyaddr(addr%)
 3740LOCAL ptr%,flags%:!socktemp%=addr%
 3750REM "XInternet_GetHostByAddr"
 3760SYS &66001,0,socktemp%,4,AF_INET TOr,ptr%;flags%
 3770REM IF (flags% AND 1) THENPRINTFNstring0(r+4)
 3780IF ptr%=0 OR (flags% AND 1)=1 THEN=STR$(socktemp%?0)+"."+STR$(socktemp%?1)+"."+STR$(socktemp%?2)+"."+STR$(socktemp%?3)
 3790=FNstring0(!ptr%)
 3800:
 3810REM FNinet_createservmenu : Create a menu of services
 3820DEFFNinet_createservmenu(name$,proto$)
 3830LOCAL menu%
 3840IF proto$="" THEN
 3850 SYS "Internet_GetServicesMenu",name$,0 TO menu%
 3860ELSE
 3870 SYS "Internet_GetServicesMenu",name$,proto$ TO menu%
 3880ENDIF
 3890=menu%
 3900:
 3910REM FNinet_decodeerror : Decodes an error into a string
 3920DEFFNinet_decodeerror(err%)
 3930LOCAL a$:SYS "Internet_DecodeError",err% TOa$
 3940=a$
 3950:
 3960REM ***************** Multi-tasking Resolver stuff ***************
 3970:
 3980REM FNinet_mtresolver : Is there Multitasking resolver present ?
 3990DEFFNinet_mtresolver
 4000LOCAL flags%,ptr%
 4010SYS "OS_Module",18,"DNSResolver" TO ,,,ptr%;flags%
 4020IF (flags% AND 1)=0 THEN
 4030 IF VAL(FNstring0((ptr%!10)+13))>=1.03 THEN=TRUE
 4040ENDIF
 4050=FALSE
 4060:
 4070REM FNinet_startmtgethostbyname : Start a multitasking name lookup
 4080REM Returns handle if this succeeded in starting
 4090DEFFNinet_startmtgethostbyname(host$)
 4100LOCAL ptr%,flags%
 4110SYS "XDNSResolver_MTGetHostByName",host$ TOptr%;flags%
 4120IF (flags% AND 1)=1 THEN=FALSE
 4130REM Hook us into the chain
 4140flags%=FNclaim(8):!flags%=mtchain%:flags%!4=ptr%:mtchain%=flags%
 4150=ptr%
 4160:
 4170REM FNinet_startmtgethostbyaddr : Start multitasking addr lookup
 4180REM Returns handle if this succeeded in starting
 4190DEFFNinet_startmtgethostbyaddr(addr%)
 4200LOCAL ptr%,flags%:!socktemp%=addr%
 4210SYS "XDNSResolver_MTGetHostByAddr",socktemp%,4,AF_INET TOptr%;flags%
 4220IF (flags% AND 1)=1 THEN=FALSE
 4230REM Hook us into the chain
 4240flags%=FNclaim(8):!flags%=mtchain%:flags%!4=ptr%:mtchain%=flags%
 4250=ptr%
 4260:
 4270REM FNinet_checkmtquery : Check progress of multitasking lookup
 4280REM Returns FALSE if query failed (stack failure), TRUE if
 4290REM query completed ok, and 1 if it's still going
 4300DEFFNinet_checkmtquery(query%)
 4310LOCAL res%,flags%
 4320SYS "XDNSResolver_Check",query% TO res%;flags%
 4330IF (flags% AND 1)=1 OR res%=4 THEN=FALSE ELSEIF res%=3 THEN=TRUE
 4340=1
 4350:
 4360REM PROCinet_killmtquery : Forget about a multitasking lookup
 4370DEFPROCinet_killmtquery(query%)
 4380LOCAL l%,p%,n%
 4390SYS "XDNSResolver_Dispose",query%
 4400p%=mtchain%
 4410IF p%!4=query% THEN
 4420 mtchain%=!p%:PROCrelease(p%)
 4430ELSE
 4440 l%=p%:p%=!p%
 4450 WHILE p%<>0
 4460  n%=!p%:IF p%!4=query% THENPROCrelease(p%):!l%=n%
 4470  p%=n%
 4480 ENDWHILE
 4490ENDIF
 4500ENDPROC
 4510:
 4520REM FNinet_mtgethostbyname : Retrieve an address from a hostent
 4530REM Returns the result of host lookup, or 0 if it failed
 4540DEFFNinet_mtgethostbyname(query%)
 4550LOCAL ptr%,flags%,addr%
 4560SYS "XDNSResolver_GetAnswer",query% TO ptr%;flags%
 4570IF ptr%<>0 THEN addr%=!!(ptr%!16)
 4580PROCinet_killmtquery(query%)
 4590IF ptr%=0 OR (flags% AND 1)=1 THEN=0
 4600=addr%
 4610:
 4620REM FNinet_mtgethostbyaddr : Retrieve a name from a hostent
 4630REM Returns the result of an address lookup, or "" if it failed
 4640DEFFNinet_mtgethostbyaddr(query%)
 4650LOCAL ptr%,flags%,host$
 4660SYS "XDNSResolver_GetAnswer",query% TO ptr%;flags%
 4670IF ptr%<>0 THENhost$=FNstring0(!ptr%)
 4680PROCinet_killmtquery(query%)
 4690IF ptr%=0 OR (flags% AND 1)=1 THEN=""
 4700=host$
 4710:
 4720REM ******************** Buffer routines **********************
 4730:
 4740REM FNbuffer_getword : Read the first word from a buffer
 4750DEFFNbuffer_getword(start%,len%,RETURN ptr%)
 4760LOCAL a$:a$=""
 4770WHILE start%?ptr%=32 AND ptr%<len%:ptr%+=1:ENDWHILE
 4780IF ptr%>=len% THEN=""
 4790REPEAT
 4800 a$+=CHR$(start%?ptr%):ptr%+=1
 4810UNTIL start%?ptr%=32 ORstart%?ptr%=10 ORstart%?ptr%=13 ORstart%?ptr%=0 ORptr%=len%
 4820IF start%?ptr%=32 AND ptr%<>len% THENptr%+=1
 4830=a$
 4840:
 4850REM FNbuffer_getrest : Read the rest of the buffer to a string
 4860DEFFNbuffer_getrest(start%,len%,RETURN ptr%)
 4870LOCAL a$:a$=""
 4880WHILE (NOT (start%?ptr%=10 ORstart%?ptr%=13 OR start%?ptr%=0 ORptr%=len%)) AND LEN(a$)<254
 4890 a$+=CHR$(start%?ptr%):ptr%+=1
 4900ENDWHILE
 4910IF (start%?ptr%=10 ORstart%?ptr%=13 OR start%?ptr%=0) AND ptr%<>len% THENptr%+=1
 4920=a$
 4930:
 4940REM ********************* Logging routines ********************
 4950:
 4960REM PROCsyslog : log a line to the log file
 4970DEFPROCsyslog(l%,m$)
 4980REM XSysLog_LogMessage
 4990SYS &6C880,Appname$,m$,l%
 5000ENDPROC
 5010:
 5020REM FNlog_opensession : Start a session log
 5030DEFFNlog_opensession(l%)
 5040REM XSysLog_OpenSessionLog
 5050SYS &6C888,Appname$,l% TO l%
 5060=l%
 5070:
 5080REM PROClog_closesession
 5090DEFPROClog_closesession(l%)
 5100REM XSysLog_CloseSessionLog
 5110SYS &6C889,l%
 5120ENDPROC
 5130:
 5140REM FNlog_session : Log a line to a session log
 5150DEFPROClog_session(log%,l%,m$)
 5160REM XSysLog_LogMessage
 5170SYS &6C880,log%,m$,l%
 5180ENDPROC
 5190:
 5200REM PROClog_indent : indent the log file
 5210DEFPROClog_indent(l%)
 5220REM XSysLog_Indent
 5230IF l%<>-1 THENSYS &6C885,l% ELSESYS &6C885,Appname$
 5240ENDPROC
 5250:
 5260REM PROClog_outdent : remove indent from the log file
 5270DEFPROClog_outdent(l%)
 5280REM XSysLog_UnIndent
 5290IF l%<>-1 THENSYS &6C886,l% ELSESYS &6C886,Appname$
 5300ENDPROC
 5310:
 5320REM PROClog_data : Log a data block
 5330DEFPROClog_data(log%,l%,d%,len%,b%)
 5340REM XSysLog_LogData
 5350IF log%<>-1 THENSYS &6C88A,log%,l%,d%,len%,b% ELSESYS &6C88A,Appname$,l%,d%,len%,b%
 5360ENDPROC

� >SocketLib
� � Justin Fletcher
"� Version : 1.11 (15 Jun 1997)
(4� Tested with Acorn !Internet and FreeNet suites
2(� Massively bug-fixed by Dave Thomas
<?� Non-blocking connect and DNS query added by Reuben Thomas
F*� &803,"Do not run the Socket Library"
P:
Z6� PROCinitsockets : Initialise the sockets library
d��initsockets
n9ș "XOS_SWINumberFromString",,"Socket_Creat" �;flags%
xt� (flags% �1) �reply=�errorbox("SocketLib","This application requires an internet suite to be installed.",%10):�
�G*RMEnsure InetServices 1.07 RMLoad System:Modules.Network.IServices
�:*RMEnsure InetServices 1.07 Set NoIServicesModule True
��� �systemvar("NoIServicesModule")="True" ��("Unset NoIServicesModule"):reply=�errorbox("SocketLib","This application requires a later version of the IServices module - this can be obtained with JFShared 2.42.",%10):�
�� Initialise error stuff
�sockerr%=&805
�B� Handles point to the descriptor blocks which give us details
�� about the sockets
�+� sock%(256),sockaddr% 16,socktemp% 256
�sock%()=-1
�� Socket blocks :
��  !0  = socket handle
��  !4  = Buffered address
�#�  !8  = Size of data in buffer
�  !C  = flags :
:�         b0 = Listening (0 = Speaking, 1 = Listening)
�         b1 = Buffered
"'�         b2 = Non-blocking connect
,� Total size &10
6socksize%=&10
@� Initialise buffered stuff
J<sockbuflen%=1024*2:� 2k should be enough for most things
T?sockline%=�claim(sockbuflen%):� For copying the string into
^*� Read the number of handles available
h%ș "Socket_Gettsize" � socktsize%
r� Initialise constants
|FIONREAD=&4004667F
�FIONBIO=&8004667E
�SO_SNDBUF=&1001
�SO_RCVBUF=&1002
�
AF_INET=2
�(� Multitasking chain of handles used
�mtchain%=0
��
�:
�@� FNsocket_findhandle : Find a socket handle and claim space
�ݤsocket_findhandle
�
�sock%,o%
�5sock%=-1:�:sock%+=1:� sock%(sock%)=-1 � sock%=256
�� sock%=256 �=-1
"sock%(sock%)=�claim(socksize%)
� sock%(sock%)<0 �=-1
,�o%=0�socksize%-4 �4:sock%(sock%)!o%=0:�
&
=sock%
0:
::� FNsocket_createinet : Make a socket for internet use
Dݤsocket_createinet
N#�sock%:sock%=�socket_findhandle
X� sock%=-1 �=-1
b0� PF_INET, SOCK_STREAM, and default protocol
l,ș "Socket_Creat",2,1,0 � sock%(sock%)!0
v4� sock%(sock%)!0=-1 � �release(sock%(sock%)):=-1
�
=sock%
�:
���socket_check(sock%,r$)
�?� sock%<0 �sock%>256 �� sockerr%,r$+": Socket out of range"
�>� sock%(sock%)<0 �� sockerr%,r$+": Socket has been closed"
��
�:
�7� PROCsocket_listen : Listen on a particular socket
�$��socket_listen(sock%,ip%,port%)
�"�flags%,r0:port%=port% � &FFFF
�!�socket_check(sock%,"Listen")
�?sockaddr%!0=AF_INET �((port% �256)<<16) �((port% �256)<<24)
�&sockaddr%!4=ip%:� In reverse order
+sockaddr%!8=0:sockaddr%!12=0:� Reserved
<ș "XSocket_Bind",sock%(sock%)!0,sockaddr%,16 �r0;flags%
7� (flags% �1)=1 �� sockerr%,"Bind: "+�string0(r0+4)
 #� Mark as a non-blocking socket
*E!socktemp%=-1:ș "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
4� Make it listen
><ș "XSocket_Listen",sock%(sock%)!0,5 :� 5 is the backlog
H,� Mark as listening (ie we're answering)
R/sock%(sock%)!&C=(sock%(sock%)!&C � � 1) � 1
\�
f:
pC� FNsocket_findlisten : Listen on a socket, jumping on if error
z/ݤsocket_findlisten(sock%,ip%,port%,limit%)
�"�flags%,r0:port%=port% � &FFFF
�%�socket_check(sock%,"FindListen")
��
�@ sockaddr%!0=AF_INET �((port% �256)<<16) �((port% �256)<<24)
�' sockaddr%!4=ip%:� In reverse order
�, sockaddr%!8=0:sockaddr%!12=0:� Reserved
�= ș "XSocket_Bind",sock%(sock%)!0,sockaddr%,16 �r0;flags%
�( � (flags% �1)=1 �port%+=1:limit%-=1
�� (flags% �1)=0 � limit%<0
�� limit%<0 �=-1
�#� Mark as a non-blocking socket
�E!socktemp%=-1:ș "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
�� Make it listen
<ș "XSocket_Listen",sock%(sock%)!0,5 :� 5 is the backlog
,� Mark as listening (ie we're answering)
/sock%(sock%)!&C=(sock%(sock%)!&C � � 1) � 1
$
=port%
.:
81� FNsocket_connect : Connect to a remote host
B%ݤsocket_connect(sock%,ip%,port%)
L �flags%,r0:port%=port%�&FFFF
V"�socket_check(sock%,"Connect")
`� AF_INET and port number
j;sockaddr%!0=2 � ((port% �256)<<16) � ((port% �256)<<24)
t&sockaddr%!4=ip%:� In reverse order
~+sockaddr%!8=0:sockaddr%!12=0:� Reserved
�?ș "XSocket_Connect",sock%(sock%)!0,sockaddr%,16 �r0;flags%
�� (flags% �1)=1 �=�
�#� Mark as a non-blocking socket
�E!socktemp%=-1:ș "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
�5� Mark as talking (ie we're doing the connecting)
�+sock%(sock%)!&C=(sock%(sock%)!&C � � 1)
�=�
�:
�8� FNsocket_noblockconnect : Connect without blocking
�7� Returns FALSE if couldn't connect, TRUE if it did
�*� and -TRUE if it is currently trying.
�,ݤsocket_noblockconnect(sock%,ip%,port%)
%�flags%,r0,res%:port%=port%�&FFFF

"�socket_check(sock%,"Connect")
#� Mark as a non-blocking socket
E!socktemp%=-1:ș "XSocket_Ioctl",sock%(sock%)!0,FIONBIO,socktemp%
(� AF_INET and port number
2;sockaddr%!0=2 � ((port% �256)<<16) � ((port% �256)<<24)
<&sockaddr%!4=ip%:� In reverse order
F+sockaddr%!8=0:sockaddr%!12=0:� Reserved
P?ș "XSocket_Connect",sock%(sock%)!0,sockaddr%,16 �r0;flags%
Z� (flags% �1)=1 �
d' � Check for error EINPROGRESS (36)
n � !r0=36 �res%=1 �=�
x�
�' � Otherwise it's connected already
� res%=�
��
�-� Mark as talking, and we're non-blocking
�/sock%(sock%)!&C=(sock%(sock%)!&C � � 1) � 4
�	=res%
�:
�+� FNsocket_accept : Accept a connection
�ݤsocket_accept(main%)
�!�socket_check(main%,"Accept")
�+� skt%,sock%,O:sock%=�socket_findhandle
�� sock%=-1 �=-1
�!socktemp%=16
Hș "XSocket_Accept",sock%(main%)!0,sockaddr%,socktemp% � skt%;flags%
:� (flags% � 1)=1 � skt%=-1 ��release(sock%(sock%)):=-1
sock%(sock%)!0=skt%
"� Copy the socket block
,9�O=4� socksize%-4 � 4:sock%(sock%)!O=sock%(main%)!O:�
6>� If it is a buffered socket then claim some memory for it
@!� ((sock%(main%)!&C) � 2)=2 �
J' sock%(sock%)!4=�claim(sockbuflen%)
T � sock%(sock%)!4<0 �
^"  � Not enough memory to claim
h  �release(sock%(sock%))
r	  =-1
| �
�* sock%(sock%)!8=0:� No bytes in buffer
��
�
=sock%
�:
�� ******** NOTE ******
�@� Two calls not included in the SH manual or distributed yet
�A� PROCsocket_recvbuffer : Sets the size of the receive buffer
�)��socket_recvbuffer(sock%,!socktemp%)
�%�socket_check(sock%,"RecvBuffer")
�Eș "Socket_Setsockopt",sock%(sock%)!0,&FFFF,SO_RCVBUF,socktemp%,4
��
�:
�>� PROCsocket_sendbuffer : Sets the size of the send buffer
)��socket_sendbuffer(sock%,!socktemp%)
%�socket_check(sock%,"RecvBuffer")
Eș "Socket_Setsockopt",sock%(sock%)!0,&FFFF,SO_SNDBUF,socktemp%,4
&�
0:
:A� PROCsocket_makebuffered : Ensures that a socket is buffered
D ��socket_makebuffered(sock%)
N'�socket_check(sock%,"MakeBuffered")
X"� ((sock%(sock%)!&C) � 2)=2 ��
b&sock%(sock%)!4=�claim(sockbuflen%)
lP� sock%(sock%)!4<0 �� sockerr%,"MakeBuffered: Could not claim enough memory"
v)sock%(sock%)!8=0:� No bytes in buffer
�)sock%(sock%)!&C=(sock%(sock%)!&C) � 2
��
�:
�?� PROCsocket_makelinger : Socket will (not) linger on close
�$��socket_makelinger(sock%,time%)
�%�socket_check(sock%,"MakeLinger")
�-socktemp%!0=1+(time%=0):socktemp%!4=time%
�@ș "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&80,socktemp%,8
��
�:
�@� PROCsocket_makereusable : Socket can be reused when closed
�&��socket_makereusable(sock%,flag%)
�'�socket_check(sock%,"MakeReusable")
socktemp%!0=-(flag%<>0)
?ș "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&4,socktemp%,4
Aș "XSocket_Setsockopt",sock%(sock%)!0,&FFFF,&200,socktemp%,4
 �
*:
4>� PROCclosesockets : Kill all active sockets and closedown
>��closesockets
H� I%,s%
R'�I%=0�256:s%=I%:�socket_close(s%):�
\�release(sockline%)
f0ȕ mtchain%<>0:�inet_killmtquery(mtchain%):�
p�
z:
�,� PROCsocket_close : Close a socket down
���socket_close(� sock%)
�� sock%>=0 � sock%<=256 �
� � sock%(sock%)>-1 �
�,  ș "XSocket_Shutdown",sock%(sock%)!0,2
�'  ș "XSocket_Close",sock%(sock%)!0
�<  � ((sock%(sock%)!&C) � 2)=2 ��release(sock%(sock%)!&4)
�  �release(sock%(sock%))
� �
��
�sock%=-1
��
�:
	=� FNsocket_inbuffer : Read amount of data in input buffer
	ݤsocket_inbuffer(sock%)
	#�socket_check(sock%,"InBuffer")
	$8ș "XSocket_Ioctl",sock%(sock%)!0,FIONREAD,socktemp%
	.=!socktemp%
	8:
	B<� FNsocket_eof : Return TRUE if the other end has closed
	Lݤsocket_eof(sock%)
	V�socket_check(sock%,"Eof")
	`%� ok,f%:ok=�socket_ready(sock%,�)
	j
� ok<>0 �
	t � MSG_PEEK + MSG_DONTWAIT
	~@ ș "XSocket_Recv",sock%(sock%)!0,socktemp%,1,&2+&80 � ok;f%
	� ok=(ok=0) � (f% �1)=1
	��
	�=ok
	�:
	�7� FNsocket_ready : Check whether a socket is usable
	�ݤsocket_ready(sock%,read%)
	� �socket_check(sock%,"Ready")
	�8� I,fd%,b%,ok%,r%,w%:fd%=sock%(sock%)!0:b%=socktemp%
	�9� I=0 � ((socktsize%/8+3) � �3)-1 � 4:socktemp%!I=0:�
	�1ȕ fd%>=32:b%+=4:fd%-=32:�:!b%=!b% � (1<<fd%)
	�2b%=socktemp%+I:!b%=0:b%!4=0:� immediate return
	�'� read% �r%=socktemp% �w%=socktemp%
2ș "Socket_Select",socktsize%,r%,w%,0,b% � ok%

=ok%
:
8� FNsocket_connected : Check if we are connected yet
(,� TRUE if we are, FALSE if working on it
2� error, otherwise
<ݤsocket_connected(sock%)
F� ok,f%
P� MSG_PEEK + MSG_DONTWAIT
Z?ș "XSocket_Recv",sock%(sock%)!0,socktemp%,1,&2+&80 � ok;f%
d� (f% �1) �
n0 ok=!ok:� ok=35 �ok=� �� ok=36 � ok=57 �ok=�
x�
�	 ok=�
��
�=ok
�:
�/� FNsocket_readdata : Read data into buffer
�%ݤsocket_readdata(sock%,� start%)
�� read%:read%=0
�#�socket_check(sock%,"ReadData")
�D� Read data from socket to our buffer if buffered, else to users
�6� ((sock%(sock%)!&C) � 2)=2 �start%=sock%(sock%)!4
�y� start%<&8000 �� sockerr%,"ReadData: Stupid address for socket_readdata ("+�~start%+"), flags = "+�(sock%(sock%)!&C)
�!� �socket_inbuffer(sock%)>0 �
�? ș "Socket_Read",sock%(sock%)!0,start%,sockbuflen% � read%
�

=read%
:
"=� FNsocket_readline : Read a line into a temporary buffer
,9� Line will be in a temporary buffer, terminated by 0
6?� -1 will be returned if no complete line has been received
@%ݤsocket_readline(sock%,� start%)
J� buf%,ofs%,I%,O%,read%
T#�socket_check(sock%,"ReadLine")
^\� (sock%(sock%)!&C � 2)=0 �� sockerr%,"ReadLine: Non-buffered socket_readline attempted"
h
start%=-1
r)� Read data from socket to our buffer
|+buf%=sock%(sock%)!4:ofs%=sock%(sock%)!8
�!� �socket_inbuffer(sock%)>0 �
�[ � buf%<&8000 �� sockerr%,"ReadLine: Stupid address for socket_readline ("+�~start%+")"
�G ș "Socket_Read",sock%(sock%)!0,buf%+ofs%,sockbuflen%-ofs% � read%
�E � read%<1 �� sockerr%,"ReadLine: Didn't read anything ? "+�read%
� ofs%=ofs%+read%
��
�� ofs%=0 �=-1
�� I%=0� ofs%-1
� � buf%?I%=0 �buf%?I%=13
�  � buf%?I%=10 � buf%?I%=13 �
�)  � Copy line to buffer and terminate
�%  �O%=0�I%:sockline%?O%=buf%?O%:�
�  sockline%?I%=0
3  � Copy remainder of buffer to start of buffer
0  �O%=I%+1 � ofs%-1:buf%?(O%-I%-1)=buf%?O%:�
$  ofs%-=I%+1:sock%(sock%)!8=ofs%
&%  � Return with buffer and length
0  start%=sockline%:=I%+1
: �
D�
Nsock%(sock%)!8=ofs%
X=-1
b:
l5� PROCsocket_sendline : Send a string to a socket
v��socket_sendline(sock%,m$)
�� r0,flags%
�#�socket_check(sock%,"SendLine")
�$(socktemp%)=m$+�10
�Bș "XSocket_Write",sock%(sock%)!0,socktemp%,�(m$)+1 �r0;flags%
�F� IF (flags% AND 1)=1 THENERROR sockerr%,"Write: "+FNstring0(r0+4)
�7� r0<>�(m$)+1 �� sockerr%,"Could not send all data"
��
�:
�1� PROCsocket_senddata : Send data to a socket
�$��socket_senddata(sock%,b%,len%)
�� r0,flags%
�#�socket_check(sock%,"SendData")
�8ș "XSocket_Write",sock%(sock%)!0,b%,len% �r0;flags%

F� IF (flags% AND 1)=1 THENERROR sockerr%,"Write: "+FNstring0(r0+4)

�

:

 ;� FNsocket_getpeername : Read the name of the other end

*ݤsocket_getpeername(sock%)

4� r0,r1

>&�socket_check(sock%,"GetPeerName")

H!socktemp%=16

R>ș "Socket_Getpeername",sock%(sock%)!0,sockaddr%,socktemp%

\� "XInternet_GetHostByAddr"

f2ș &66001,0,sockaddr%+4,4,AF_INET � ,r1;flags%

p+� (flags% �1)=0 � r1<>0 �=�string0(!r1)

zL=�(sockaddr%?4)+"."+�(sockaddr%?5)+"."+�(sockaddr%?6)+"."+�(sockaddr%?7)

�:

�A� **************** Host and service specific ****************

�:

�<� FNinet_getservbyname : Read the port from service name

�&ݤinet_getservbyname(name$,proto$)

�� servent%,port%

�� �(name$)<>0 �=�(name$)

�;ș "Internet_GetServiceByName",name$,proto$ � ,servent%

�+� servent%=0 �port%=0 �port%=servent%!8

�
=port%

�:

�<� FNinet_getservbyport : Read the service name from port

�&ݤinet_getservbyport(port%,proto$)
#� servent%,s$:port%=port%�&FFFF
;ș "Internet_GetServiceByPort",port%,proto$ � ,servent%
3� servent%=0 �s$=�port% �s$=�string0(!servent%)
$=s$
.:
89� FNinet_gethostbyname : Return address of named host
Bݤinet_gethostbyname(host$)
L� ptr%,flags%
V� "XInternet_GetHostByName"
`#ș &66000,0,host$ �,ptr%;flags%
j!� ptr%=0 � (flags% � 1)=1 �=0
t1=!!(ptr%!16):� Yes, that is right, honest ;-)
~:
�C� FNinet_gethostbyaddr : Return name of host with given address
�ݤinet_gethostbyaddr(addr%)
�"� ptr%,flags%:!socktemp%=addr%
�� "XInternet_GetHostByAddr"
�2ș &66001,0,socktemp%,4,AF_INET �r,ptr%;flags%
�/� IF (flags% AND 1) THENPRINTFNstring0(r+4)
�g� ptr%=0 � (flags% � 1)=1 �=�(socktemp%?0)+"."+�(socktemp%?1)+"."+�(socktemp%?2)+"."+�(socktemp%?3)
�=�string0(!ptr%)
�:
�7� FNinet_createservmenu : Create a menu of services
�'ݤinet_createservmenu(name$,proto$)
�� menu%
� proto$="" �

2 ș "Internet_GetServicesMenu",name$,0 � menu%
�
7 ș "Internet_GetServicesMenu",name$,proto$ � menu%
(�
2
=menu%
<:
F9� FNinet_decodeerror : Decodes an error into a string
Pݤinet_decodeerror(err%)
Z+� a$:ș "Internet_DecodeError",err% �a$
d=a$
n:
xD� ***************** Multi-tasking Resolver stuff ***************
�:
�B� FNinet_mtresolver : Is there Multitasking resolver present ?
�ݤinet_mtresolver
�� flags%,ptr%
�4ș "OS_Module",18,"DNSResolver" � ,,,ptr%;flags%
�� (flags% � 1)=0 �
�* � �(�string0((ptr%!10)+13))>=1.03 �=�
��
�=�
�:
�D� FNinet_startmtgethostbyname : Start a multitasking name lookup
�2� Returns handle if this succeeded in starting
�&ݤinet_startmtgethostbyname(host$)
� ptr%,flags%
8ș "XDNSResolver_MTGetHostByName",host$ �ptr%;flags%
� (flags% � 1)=1 �=�
"� Hook us into the chain
,Cflags%=�claim(8):!flags%=mtchain%:flags%!4=ptr%:mtchain%=flags%
6	=ptr%
@:
JB� FNinet_startmtgethostbyaddr : Start multitasking addr lookup
T2� Returns handle if this succeeded in starting
^&ݤinet_startmtgethostbyaddr(addr%)
h"� ptr%,flags%:!socktemp%=addr%
rFș "XDNSResolver_MTGetHostByAddr",socktemp%,4,AF_INET �ptr%;flags%
|� (flags% � 1)=1 �=�
�� Hook us into the chain
�Cflags%=�claim(8):!flags%=mtchain%:flags%!4=ptr%:mtchain%=flags%
�	=ptr%
�:
�A� FNinet_checkmtquery : Check progress of multitasking lookup
�<� Returns FALSE if query failed (stack failure), TRUE if
�3� query completed ok, and 1 if it's still going
�ݤinet_checkmtquery(query%)
�� res%,flags%
�0ș "XDNSResolver_Check",query% � res%;flags%
�/� (flags% � 1)=1 � res%=4 �=� �� res%=3 �=�
�=1
�:
?� PROCinet_killmtquery : Forget about a multitasking lookup
��inet_killmtquery(query%)
� l%,p%,n%
&$ș "XDNSResolver_Dispose",query%
0p%=mtchain%
:� p%!4=query% �
D mtchain%=!p%:�release(p%)
N�
X l%=p%:p%=!p%
b
 ȕ p%<>0
l/  n%=!p%:� p%!4=query% ��release(p%):!l%=n%
v  p%=n%
� �
��
��
�:
�A� FNinet_mtgethostbyname : Retrieve an address from a hostent
�:� Returns the result of host lookup, or 0 if it failed
�"ݤinet_mtgethostbyname(query%)
�� ptr%,flags%,addr%
�4ș "XDNSResolver_GetAnswer",query% � ptr%;flags%
�!� ptr%<>0 � addr%=!!(ptr%!16)
��inet_killmtquery(query%)
�!� ptr%=0 � (flags% � 1)=1 �=0
�
=addr%
:
=� FNinet_mtgethostbyaddr : Retrieve a name from a hostent
A� Returns the result of an address lookup, or "" if it failed
 "ݤinet_mtgethostbyaddr(query%)
*� ptr%,flags%,host$
44ș "XDNSResolver_GetAnswer",query% � ptr%;flags%
>$� ptr%<>0 �host$=�string0(!ptr%)
H�inet_killmtquery(query%)
R"� ptr%=0 � (flags% � 1)=1 �=""
\
=host$
f:
pA� ******************** Buffer routines **********************
z:
�:� FNbuffer_getword : Read the first word from a buffer
�(ݤbuffer_getword(start%,len%,� ptr%)
�� a$:a$=""
�+ȕ start%?ptr%=32 � ptr%<len%:ptr%+=1:�
�� ptr%>=len% �=""
��
� a$+=�(start%?ptr%):ptr%+=1
�N� start%?ptr%=32 �start%?ptr%=10 �start%?ptr%=13 �start%?ptr%=0 �ptr%=len%
�*� start%?ptr%=32 � ptr%<>len% �ptr%+=1
�=a$
�:
�@� FNbuffer_getrest : Read the rest of the buffer to a string
�(ݤbuffer_getrest(start%,len%,� ptr%)
� a$:a$=""
Rȕ (� (start%?ptr%=10 �start%?ptr%=13 � start%?ptr%=0 �ptr%=len%)) � �(a$)<254
 a$+=�(start%?ptr%):ptr%+=1
$�
.L� (start%?ptr%=10 �start%?ptr%=13 � start%?ptr%=0) � ptr%<>len% �ptr%+=1
8=a$
B:
LA� ********************* Logging routines ********************
V:
`-� PROCsyslog : log a line to the log file
j��syslog(l%,m$)
t� XSysLog_LogMessage
~ș &6C880,Appname$,m$,l%
��
�:
�-� FNlog_opensession : Start a session log
�ݤlog_opensession(l%)
�� XSysLog_OpenSessionLog
�ș &6C888,Appname$,l% � l%
�=l%
�:
�� PROClog_closesession
���log_closesession(l%)
�� XSysLog_CloseSessionLog
�ș &6C889,l%
�

:
1� FNlog_session : Log a line to a session log
��log_session(log%,l%,m$)
(� XSysLog_LogMessage
2ș &6C880,log%,m$,l%
<�
F:
P*� PROClog_indent : indent the log file
Z��log_indent(l%)
d� XSysLog_Indent
n.� l%<>-1 �ș &6C885,l% �ș &6C885,Appname$
x�
�:
�7� PROClog_outdent : remove indent from the log file
���log_outdent(l%)
�� XSysLog_UnIndent
�.� l%<>-1 �ș &6C886,l% �ș &6C886,Appname$
��
�:
�%� PROClog_data : Log a data block
�"��log_data(log%,l%,d%,len%,b%)
�� XSysLog_LogData
�N� log%<>-1 �ș &6C88A,log%,l%,d%,len%,b% �ș &6C88A,Appname$,l%,d%,len%,b%
��
�
00000000  0d 00 0a 10 f4 20 3e 53  6f 63 6b 65 74 4c 69 62  |..... >SocketLib|
00000010  0d 00 14 17 f4 20 a9 20  4a 75 73 74 69 6e 20 46  |..... . Justin F|
00000020  6c 65 74 63 68 65 72 0d  00 1e 22 f4 20 56 65 72  |letcher...". Ver|
00000030  73 69 6f 6e 20 3a 20 31  2e 31 31 20 28 31 35 20  |sion : 1.11 (15 |
00000040  4a 75 6e 20 31 39 39 37  29 0d 00 28 34 f4 20 54  |Jun 1997)..(4. T|
00000050  65 73 74 65 64 20 77 69  74 68 20 41 63 6f 72 6e  |ested with Acorn|
00000060  20 21 49 6e 74 65 72 6e  65 74 20 61 6e 64 20 46  | !Internet and F|
00000070  72 65 65 4e 65 74 20 73  75 69 74 65 73 0d 00 32  |reeNet suites..2|
00000080  28 f4 20 4d 61 73 73 69  76 65 6c 79 20 62 75 67  |(. Massively bug|
00000090  2d 66 69 78 65 64 20 62  79 20 44 61 76 65 20 54  |-fixed by Dave T|
000000a0  68 6f 6d 61 73 0d 00 3c  3f f4 20 4e 6f 6e 2d 62  |homas..<?. Non-b|
000000b0  6c 6f 63 6b 69 6e 67 20  63 6f 6e 6e 65 63 74 20  |locking connect |
000000c0  61 6e 64 20 44 4e 53 20  71 75 65 72 79 20 61 64  |and DNS query ad|
000000d0  64 65 64 20 62 79 20 52  65 75 62 65 6e 20 54 68  |ded by Reuben Th|
000000e0  6f 6d 61 73 0d 00 46 2a  85 20 26 38 30 33 2c 22  |omas..F*. &803,"|
000000f0  44 6f 20 6e 6f 74 20 72  75 6e 20 74 68 65 20 53  |Do not run the S|
00000100  6f 63 6b 65 74 20 4c 69  62 72 61 72 79 22 0d 00  |ocket Library"..|
00000110  50 05 3a 0d 00 5a 36 f4  20 50 52 4f 43 69 6e 69  |P.:..Z6. PROCini|
00000120  74 73 6f 63 6b 65 74 73  20 3a 20 49 6e 69 74 69  |tsockets : Initi|
00000130  61 6c 69 73 65 20 74 68  65 20 73 6f 63 6b 65 74  |alise the socket|
00000140  73 20 6c 69 62 72 61 72  79 0d 00 64 11 dd f2 69  |s library..d...i|
00000150  6e 69 74 73 6f 63 6b 65  74 73 0d 00 6e 39 c8 99  |nitsockets..n9..|
00000160  20 22 58 4f 53 5f 53 57  49 4e 75 6d 62 65 72 46  | "XOS_SWINumberF|
00000170  72 6f 6d 53 74 72 69 6e  67 22 2c 2c 22 53 6f 63  |romString",,"Soc|
00000180  6b 65 74 5f 43 72 65 61  74 22 20 b8 3b 66 6c 61  |ket_Creat" .;fla|
00000190  67 73 25 0d 00 78 74 e7  20 28 66 6c 61 67 73 25  |gs%..xt. (flags%|
000001a0  20 80 31 29 20 8c 72 65  70 6c 79 3d a4 65 72 72  | .1) .reply=.err|
000001b0  6f 72 62 6f 78 28 22 53  6f 63 6b 65 74 4c 69 62  |orbox("SocketLib|
000001c0  22 2c 22 54 68 69 73 20  61 70 70 6c 69 63 61 74  |","This applicat|
000001d0  69 6f 6e 20 72 65 71 75  69 72 65 73 20 61 6e 20  |ion requires an |
000001e0  69 6e 74 65 72 6e 65 74  20 73 75 69 74 65 20 74  |internet suite t|
000001f0  6f 20 62 65 20 69 6e 73  74 61 6c 6c 65 64 2e 22  |o be installed."|
00000200  2c 25 31 30 29 3a e0 0d  00 82 47 2a 52 4d 45 6e  |,%10):....G*RMEn|
00000210  73 75 72 65 20 49 6e 65  74 53 65 72 76 69 63 65  |sure InetService|
00000220  73 20 31 2e 30 37 20 52  4d 4c 6f 61 64 20 53 79  |s 1.07 RMLoad Sy|
00000230  73 74 65 6d 3a 4d 6f 64  75 6c 65 73 2e 4e 65 74  |stem:Modules.Net|
00000240  77 6f 72 6b 2e 49 53 65  72 76 69 63 65 73 0d 00  |work.IServices..|
00000250  8c 3a 2a 52 4d 45 6e 73  75 72 65 20 49 6e 65 74  |.:*RMEnsure Inet|
00000260  53 65 72 76 69 63 65 73  20 31 2e 30 37 20 53 65  |Services 1.07 Se|
00000270  74 20 4e 6f 49 53 65 72  76 69 63 65 73 4d 6f 64  |t NoIServicesMod|
00000280  75 6c 65 20 54 72 75 65  0d 00 96 dc e7 20 a4 73  |ule True..... .s|
00000290  79 73 74 65 6d 76 61 72  28 22 4e 6f 49 53 65 72  |ystemvar("NoISer|
000002a0  76 69 63 65 73 4d 6f 64  75 6c 65 22 29 3d 22 54  |vicesModule")="T|
000002b0  72 75 65 22 20 8c ff 28  22 55 6e 73 65 74 20 4e  |rue" ..("Unset N|
000002c0  6f 49 53 65 72 76 69 63  65 73 4d 6f 64 75 6c 65  |oIServicesModule|
000002d0  22 29 3a 72 65 70 6c 79  3d a4 65 72 72 6f 72 62  |"):reply=.errorb|
000002e0  6f 78 28 22 53 6f 63 6b  65 74 4c 69 62 22 2c 22  |ox("SocketLib","|
000002f0  54 68 69 73 20 61 70 70  6c 69 63 61 74 69 6f 6e  |This application|
00000300  20 72 65 71 75 69 72 65  73 20 61 20 6c 61 74 65  | requires a late|
00000310  72 20 76 65 72 73 69 6f  6e 20 6f 66 20 74 68 65  |r version of the|
00000320  20 49 53 65 72 76 69 63  65 73 20 6d 6f 64 75 6c  | IServices modul|
00000330  65 20 2d 20 74 68 69 73  20 63 61 6e 20 62 65 20  |e - this can be |
00000340  6f 62 74 61 69 6e 65 64  20 77 69 74 68 20 4a 46  |obtained with JF|
00000350  53 68 61 72 65 64 20 32  2e 34 32 2e 22 2c 25 31  |Shared 2.42.",%1|
00000360  30 29 3a e0 0d 00 a0 1c  f4 20 49 6e 69 74 69 61  |0):...... Initia|
00000370  6c 69 73 65 20 65 72 72  6f 72 20 73 74 75 66 66  |lise error stuff|
00000380  0d 00 aa 11 73 6f 63 6b  65 72 72 25 3d 26 38 30  |....sockerr%=&80|
00000390  35 0d 00 b4 42 f4 20 48  61 6e 64 6c 65 73 20 70  |5...B. Handles p|
000003a0  6f 69 6e 74 20 74 6f 20  74 68 65 20 64 65 73 63  |oint to the desc|
000003b0  72 69 70 74 6f 72 20 62  6c 6f 63 6b 73 20 77 68  |riptor blocks wh|
000003c0  69 63 68 20 67 69 76 65  20 75 73 20 64 65 74 61  |ich give us deta|
000003d0  69 6c 73 0d 00 be 17 f4  20 61 62 6f 75 74 20 74  |ils..... about t|
000003e0  68 65 20 73 6f 63 6b 65  74 73 0d 00 c8 2b de 20  |he sockets...+. |
000003f0  73 6f 63 6b 25 28 32 35  36 29 2c 73 6f 63 6b 61  |sock%(256),socka|
00000400  64 64 72 25 20 31 36 2c  73 6f 63 6b 74 65 6d 70  |ddr% 16,socktemp|
00000410  25 20 32 35 36 0d 00 d2  0e 73 6f 63 6b 25 28 29  |% 256....sock%()|
00000420  3d 2d 31 0d 00 dc 15 f4  20 53 6f 63 6b 65 74 20  |=-1..... Socket |
00000430  62 6c 6f 63 6b 73 20 3a  0d 00 e6 1a f4 20 20 21  |blocks :.....  !|
00000440  30 20 20 3d 20 73 6f 63  6b 65 74 20 68 61 6e 64  |0  = socket hand|
00000450  6c 65 0d 00 f0 1d f4 20  20 21 34 20 20 3d 20 42  |le.....  !4  = B|
00000460  75 66 66 65 72 65 64 20  61 64 64 72 65 73 73 0d  |uffered address.|
00000470  00 fa 23 f4 20 20 21 38  20 20 3d 20 53 69 7a 65  |..#.  !8  = Size|
00000480  20 6f 66 20 64 61 74 61  20 69 6e 20 62 75 66 66  | of data in buff|
00000490  65 72 0d 01 04 14 f4 20  20 21 43 20 20 3d 20 66  |er.....  !C  = f|
000004a0  6c 61 67 73 20 3a 0d 01  0e 3a f4 20 20 20 20 20  |lags :...:.     |
000004b0  20 20 20 20 62 30 20 3d  20 4c 69 73 74 65 6e 69  |    b0 = Listeni|
000004c0  6e 67 20 28 30 20 3d 20  53 70 65 61 6b 69 6e 67  |ng (0 = Speaking|
000004d0  2c 20 31 20 3d 20 4c 69  73 74 65 6e 69 6e 67 29  |, 1 = Listening)|
000004e0  0d 01 18 1b f4 20 20 20  20 20 20 20 20 20 62 31  |.....         b1|
000004f0  20 3d 20 42 75 66 66 65  72 65 64 0d 01 22 27 f4  | = Buffered.."'.|
00000500  20 20 20 20 20 20 20 20  20 62 32 20 3d 20 4e 6f  |         b2 = No|
00000510  6e 2d 62 6c 6f 63 6b 69  6e 67 20 63 6f 6e 6e 65  |n-blocking conne|
00000520  63 74 0d 01 2c 14 f4 20  54 6f 74 61 6c 20 73 69  |ct..,.. Total si|
00000530  7a 65 20 26 31 30 0d 01  36 11 73 6f 63 6b 73 69  |ze &10..6.socksi|
00000540  7a 65 25 3d 26 31 30 0d  01 40 1f f4 20 49 6e 69  |ze%=&10..@.. Ini|
00000550  74 69 61 6c 69 73 65 20  62 75 66 66 65 72 65 64  |tialise buffered|
00000560  20 73 74 75 66 66 0d 01  4a 3c 73 6f 63 6b 62 75  | stuff..J<sockbu|
00000570  66 6c 65 6e 25 3d 31 30  32 34 2a 32 3a f4 20 32  |flen%=1024*2:. 2|
00000580  6b 20 73 68 6f 75 6c 64  20 62 65 20 65 6e 6f 75  |k should be enou|
00000590  67 68 20 66 6f 72 20 6d  6f 73 74 20 74 68 69 6e  |gh for most thin|
000005a0  67 73 0d 01 54 3f 73 6f  63 6b 6c 69 6e 65 25 3d  |gs..T?sockline%=|
000005b0  a4 63 6c 61 69 6d 28 73  6f 63 6b 62 75 66 6c 65  |.claim(sockbufle|
000005c0  6e 25 29 3a f4 20 46 6f  72 20 63 6f 70 79 69 6e  |n%):. For copyin|
000005d0  67 20 74 68 65 20 73 74  72 69 6e 67 20 69 6e 74  |g the string int|
000005e0  6f 0d 01 5e 2a f4 20 52  65 61 64 20 74 68 65 20  |o..^*. Read the |
000005f0  6e 75 6d 62 65 72 20 6f  66 20 68 61 6e 64 6c 65  |number of handle|
00000600  73 20 61 76 61 69 6c 61  62 6c 65 0d 01 68 25 c8  |s available..h%.|
00000610  99 20 22 53 6f 63 6b 65  74 5f 47 65 74 74 73 69  |. "Socket_Gettsi|
00000620  7a 65 22 20 b8 20 73 6f  63 6b 74 73 69 7a 65 25  |ze" . socktsize%|
00000630  0d 01 72 1a f4 20 49 6e  69 74 69 61 6c 69 73 65  |..r.. Initialise|
00000640  20 63 6f 6e 73 74 61 6e  74 73 0d 01 7c 16 46 49  | constants..|.FI|
00000650  4f 4e 52 45 41 44 3d 26  34 30 30 34 36 36 37 46  |ONREAD=&4004667F|
00000660  0d 01 86 15 46 49 4f 4e  42 49 4f 3d 26 38 30 30  |....FIONBIO=&800|
00000670  34 36 36 37 45 0d 01 90  13 53 4f 5f 53 4e 44 42  |4667E....SO_SNDB|
00000680  55 46 3d 26 31 30 30 31  0d 01 9a 13 53 4f 5f 52  |UF=&1001....SO_R|
00000690  43 56 42 55 46 3d 26 31  30 30 32 0d 01 a4 0d 41  |CVBUF=&1002....A|
000006a0  46 5f 49 4e 45 54 3d 32  0d 01 ae 28 f4 20 4d 75  |F_INET=2...(. Mu|
000006b0  6c 74 69 74 61 73 6b 69  6e 67 20 63 68 61 69 6e  |ltitasking chain|
000006c0  20 6f 66 20 68 61 6e 64  6c 65 73 20 75 73 65 64  | of handles used|
000006d0  0d 01 b8 0e 6d 74 63 68  61 69 6e 25 3d 30 0d 01  |....mtchain%=0..|
000006e0  c2 05 e1 0d 01 cc 05 3a  0d 01 d6 40 f4 20 46 4e  |.......:...@. FN|
000006f0  73 6f 63 6b 65 74 5f 66  69 6e 64 68 61 6e 64 6c  |socket_findhandl|
00000700  65 20 3a 20 46 69 6e 64  20 61 20 73 6f 63 6b 65  |e : Find a socke|
00000710  74 20 68 61 6e 64 6c 65  20 61 6e 64 20 63 6c 61  |t handle and cla|
00000720  69 6d 20 73 70 61 63 65  0d 01 e0 17 dd a4 73 6f  |im space......so|
00000730  63 6b 65 74 5f 66 69 6e  64 68 61 6e 64 6c 65 0d  |cket_findhandle.|
00000740  01 ea 0d ea 73 6f 63 6b  25 2c 6f 25 0d 01 f4 35  |....sock%,o%...5|
00000750  73 6f 63 6b 25 3d 2d 31  3a f5 3a 73 6f 63 6b 25  |sock%=-1:.:sock%|
00000760  2b 3d 31 3a fd 20 73 6f  63 6b 25 28 73 6f 63 6b  |+=1:. sock%(sock|
00000770  25 29 3d 2d 31 20 84 20  73 6f 63 6b 25 3d 32 35  |%)=-1 . sock%=25|
00000780  36 0d 01 fe 14 e7 20 73  6f 63 6b 25 3d 32 35 36  |6..... sock%=256|
00000790  20 8c 3d 2d 31 0d 02 08  22 73 6f 63 6b 25 28 73  | .=-1..."sock%(s|
000007a0  6f 63 6b 25 29 3d a4 63  6c 61 69 6d 28 73 6f 63  |ock%)=.claim(soc|
000007b0  6b 73 69 7a 65 25 29 0d  02 12 19 e7 20 73 6f 63  |ksize%)..... soc|
000007c0  6b 25 28 73 6f 63 6b 25  29 3c 30 20 8c 3d 2d 31  |k%(sock%)<0 .=-1|
000007d0  0d 02 1c 2c e3 6f 25 3d  30 b8 73 6f 63 6b 73 69  |...,.o%=0.socksi|
000007e0  7a 65 25 2d 34 20 88 34  3a 73 6f 63 6b 25 28 73  |ze%-4 .4:sock%(s|
000007f0  6f 63 6b 25 29 21 6f 25  3d 30 3a ed 0d 02 26 0a  |ock%)!o%=0:...&.|
00000800  3d 73 6f 63 6b 25 0d 02  30 05 3a 0d 02 3a 3a f4  |=sock%..0.:..::.|
00000810  20 46 4e 73 6f 63 6b 65  74 5f 63 72 65 61 74 65  | FNsocket_create|
00000820  69 6e 65 74 20 3a 20 4d  61 6b 65 20 61 20 73 6f  |inet : Make a so|
00000830  63 6b 65 74 20 66 6f 72  20 69 6e 74 65 72 6e 65  |cket for interne|
00000840  74 20 75 73 65 0d 02 44  17 dd a4 73 6f 63 6b 65  |t use..D...socke|
00000850  74 5f 63 72 65 61 74 65  69 6e 65 74 0d 02 4e 23  |t_createinet..N#|
00000860  ea 73 6f 63 6b 25 3a 73  6f 63 6b 25 3d a4 73 6f  |.sock%:sock%=.so|
00000870  63 6b 65 74 5f 66 69 6e  64 68 61 6e 64 6c 65 0d  |cket_findhandle.|
00000880  02 58 13 e7 20 73 6f 63  6b 25 3d 2d 31 20 8c 3d  |.X.. sock%=-1 .=|
00000890  2d 31 0d 02 62 30 f4 20  50 46 5f 49 4e 45 54 2c  |-1..b0. PF_INET,|
000008a0  20 53 4f 43 4b 5f 53 54  52 45 41 4d 2c 20 61 6e  | SOCK_STREAM, an|
000008b0  64 20 64 65 66 61 75 6c  74 20 70 72 6f 74 6f 63  |d default protoc|
000008c0  6f 6c 0d 02 6c 2c c8 99  20 22 53 6f 63 6b 65 74  |ol..l,.. "Socket|
000008d0  5f 43 72 65 61 74 22 2c  32 2c 31 2c 30 20 b8 20  |_Creat",2,1,0 . |
000008e0  73 6f 63 6b 25 28 73 6f  63 6b 25 29 21 30 0d 02  |sock%(sock%)!0..|
000008f0  76 34 e7 20 73 6f 63 6b  25 28 73 6f 63 6b 25 29  |v4. sock%(sock%)|
00000900  21 30 3d 2d 31 20 8c 20  f2 72 65 6c 65 61 73 65  |!0=-1 . .release|
00000910  28 73 6f 63 6b 25 28 73  6f 63 6b 25 29 29 3a 3d  |(sock%(sock%)):=|
00000920  2d 31 0d 02 80 0a 3d 73  6f 63 6b 25 0d 02 8a 05  |-1....=sock%....|
00000930  3a 0d 02 94 1c dd f2 73  6f 63 6b 65 74 5f 63 68  |:......socket_ch|
00000940  65 63 6b 28 73 6f 63 6b  25 2c 72 24 29 0d 02 9e  |eck(sock%,r$)...|
00000950  3f e7 20 73 6f 63 6b 25  3c 30 20 84 73 6f 63 6b  |?. sock%<0 .sock|
00000960  25 3e 32 35 36 20 8c 85  20 73 6f 63 6b 65 72 72  |%>256 .. sockerr|
00000970  25 2c 72 24 2b 22 3a 20  53 6f 63 6b 65 74 20 6f  |%,r$+": Socket o|
00000980  75 74 20 6f 66 20 72 61  6e 67 65 22 0d 02 a8 3e  |ut of range"...>|
00000990  e7 20 73 6f 63 6b 25 28  73 6f 63 6b 25 29 3c 30  |. sock%(sock%)<0|
000009a0  20 8c 85 20 73 6f 63 6b  65 72 72 25 2c 72 24 2b  | .. sockerr%,r$+|
000009b0  22 3a 20 53 6f 63 6b 65  74 20 68 61 73 20 62 65  |": Socket has be|
000009c0  65 6e 20 63 6c 6f 73 65  64 22 0d 02 b2 05 e1 0d  |en closed"......|
000009d0  02 bc 05 3a 0d 02 c6 37  f4 20 50 52 4f 43 73 6f  |...:...7. PROCso|
000009e0  63 6b 65 74 5f 6c 69 73  74 65 6e 20 3a 20 4c 69  |cket_listen : Li|
000009f0  73 74 65 6e 20 6f 6e 20  61 20 70 61 72 74 69 63  |sten on a partic|
00000a00  75 6c 61 72 20 73 6f 63  6b 65 74 0d 02 d0 24 dd  |ular socket...$.|
00000a10  f2 73 6f 63 6b 65 74 5f  6c 69 73 74 65 6e 28 73  |.socket_listen(s|
00000a20  6f 63 6b 25 2c 69 70 25  2c 70 6f 72 74 25 29 0d  |ock%,ip%,port%).|
00000a30  02 da 22 ea 66 6c 61 67  73 25 2c 72 30 3a 70 6f  |..".flags%,r0:po|
00000a40  72 74 25 3d 70 6f 72 74  25 20 80 20 26 46 46 46  |rt%=port% . &FFF|
00000a50  46 0d 02 e4 21 f2 73 6f  63 6b 65 74 5f 63 68 65  |F...!.socket_che|
00000a60  63 6b 28 73 6f 63 6b 25  2c 22 4c 69 73 74 65 6e  |ck(sock%,"Listen|
00000a70  22 29 0d 02 ee 3f 73 6f  63 6b 61 64 64 72 25 21  |")...?sockaddr%!|
00000a80  30 3d 41 46 5f 49 4e 45  54 20 84 28 28 70 6f 72  |0=AF_INET .((por|
00000a90  74 25 20 81 32 35 36 29  3c 3c 31 36 29 20 84 28  |t% .256)<<16) .(|
00000aa0  28 70 6f 72 74 25 20 83  32 35 36 29 3c 3c 32 34  |(port% .256)<<24|
00000ab0  29 0d 02 f8 26 73 6f 63  6b 61 64 64 72 25 21 34  |)...&sockaddr%!4|
00000ac0  3d 69 70 25 3a f4 20 49  6e 20 72 65 76 65 72 73  |=ip%:. In revers|
00000ad0  65 20 6f 72 64 65 72 0d  03 02 2b 73 6f 63 6b 61  |e order...+socka|
00000ae0  64 64 72 25 21 38 3d 30  3a 73 6f 63 6b 61 64 64  |ddr%!8=0:sockadd|
00000af0  72 25 21 31 32 3d 30 3a  f4 20 52 65 73 65 72 76  |r%!12=0:. Reserv|
00000b00  65 64 0d 03 0c 3c c8 99  20 22 58 53 6f 63 6b 65  |ed...<.. "XSocke|
00000b10  74 5f 42 69 6e 64 22 2c  73 6f 63 6b 25 28 73 6f  |t_Bind",sock%(so|
00000b20  63 6b 25 29 21 30 2c 73  6f 63 6b 61 64 64 72 25  |ck%)!0,sockaddr%|
00000b30  2c 31 36 20 b8 72 30 3b  66 6c 61 67 73 25 0d 03  |,16 .r0;flags%..|
00000b40  16 37 e7 20 28 66 6c 61  67 73 25 20 80 31 29 3d  |.7. (flags% .1)=|
00000b50  31 20 8c 85 20 73 6f 63  6b 65 72 72 25 2c 22 42  |1 .. sockerr%,"B|
00000b60  69 6e 64 3a 20 22 2b a4  73 74 72 69 6e 67 30 28  |ind: "+.string0(|
00000b70  72 30 2b 34 29 0d 03 20  23 f4 20 4d 61 72 6b 20  |r0+4).. #. Mark |
00000b80  61 73 20 61 20 6e 6f 6e  2d 62 6c 6f 63 6b 69 6e  |as a non-blockin|
00000b90  67 20 73 6f 63 6b 65 74  0d 03 2a 45 21 73 6f 63  |g socket..*E!soc|
00000ba0  6b 74 65 6d 70 25 3d 2d  31 3a c8 99 20 22 58 53  |ktemp%=-1:.. "XS|
00000bb0  6f 63 6b 65 74 5f 49 6f  63 74 6c 22 2c 73 6f 63  |ocket_Ioctl",soc|
00000bc0  6b 25 28 73 6f 63 6b 25  29 21 30 2c 46 49 4f 4e  |k%(sock%)!0,FION|
00000bd0  42 49 4f 2c 73 6f 63 6b  74 65 6d 70 25 0d 03 34  |BIO,socktemp%..4|
00000be0  14 f4 20 4d 61 6b 65 20  69 74 20 6c 69 73 74 65  |.. Make it liste|
00000bf0  6e 0d 03 3e 3c c8 99 20  22 58 53 6f 63 6b 65 74  |n..><.. "XSocket|
00000c00  5f 4c 69 73 74 65 6e 22  2c 73 6f 63 6b 25 28 73  |_Listen",sock%(s|
00000c10  6f 63 6b 25 29 21 30 2c  35 20 3a f4 20 35 20 69  |ock%)!0,5 :. 5 i|
00000c20  73 20 74 68 65 20 62 61  63 6b 6c 6f 67 0d 03 48  |s the backlog..H|
00000c30  2c f4 20 4d 61 72 6b 20  61 73 20 6c 69 73 74 65  |,. Mark as liste|
00000c40  6e 69 6e 67 20 28 69 65  20 77 65 27 72 65 20 61  |ning (ie we're a|
00000c50  6e 73 77 65 72 69 6e 67  29 0d 03 52 2f 73 6f 63  |nswering)..R/soc|
00000c60  6b 25 28 73 6f 63 6b 25  29 21 26 43 3d 28 73 6f  |k%(sock%)!&C=(so|
00000c70  63 6b 25 28 73 6f 63 6b  25 29 21 26 43 20 80 20  |ck%(sock%)!&C . |
00000c80  ac 20 31 29 20 84 20 31  0d 03 5c 05 e1 0d 03 66  |. 1) . 1..\....f|
00000c90  05 3a 0d 03 70 43 f4 20  46 4e 73 6f 63 6b 65 74  |.:..pC. FNsocket|
00000ca0  5f 66 69 6e 64 6c 69 73  74 65 6e 20 3a 20 4c 69  |_findlisten : Li|
00000cb0  73 74 65 6e 20 6f 6e 20  61 20 73 6f 63 6b 65 74  |sten on a socket|
00000cc0  2c 20 6a 75 6d 70 69 6e  67 20 6f 6e 20 69 66 20  |, jumping on if |
00000cd0  65 72 72 6f 72 0d 03 7a  2f dd a4 73 6f 63 6b 65  |error..z/..socke|
00000ce0  74 5f 66 69 6e 64 6c 69  73 74 65 6e 28 73 6f 63  |t_findlisten(soc|
00000cf0  6b 25 2c 69 70 25 2c 70  6f 72 74 25 2c 6c 69 6d  |k%,ip%,port%,lim|
00000d00  69 74 25 29 0d 03 84 22  ea 66 6c 61 67 73 25 2c  |it%)...".flags%,|
00000d10  72 30 3a 70 6f 72 74 25  3d 70 6f 72 74 25 20 80  |r0:port%=port% .|
00000d20  20 26 46 46 46 46 0d 03  8e 25 f2 73 6f 63 6b 65  | &FFFF...%.socke|
00000d30  74 5f 63 68 65 63 6b 28  73 6f 63 6b 25 2c 22 46  |t_check(sock%,"F|
00000d40  69 6e 64 4c 69 73 74 65  6e 22 29 0d 03 98 05 f5  |indListen").....|
00000d50  0d 03 a2 40 20 73 6f 63  6b 61 64 64 72 25 21 30  |...@ sockaddr%!0|
00000d60  3d 41 46 5f 49 4e 45 54  20 84 28 28 70 6f 72 74  |=AF_INET .((port|
00000d70  25 20 81 32 35 36 29 3c  3c 31 36 29 20 84 28 28  |% .256)<<16) .((|
00000d80  70 6f 72 74 25 20 83 32  35 36 29 3c 3c 32 34 29  |port% .256)<<24)|
00000d90  0d 03 ac 27 20 73 6f 63  6b 61 64 64 72 25 21 34  |...' sockaddr%!4|
00000da0  3d 69 70 25 3a f4 20 49  6e 20 72 65 76 65 72 73  |=ip%:. In revers|
00000db0  65 20 6f 72 64 65 72 0d  03 b6 2c 20 73 6f 63 6b  |e order..., sock|
00000dc0  61 64 64 72 25 21 38 3d  30 3a 73 6f 63 6b 61 64  |addr%!8=0:sockad|
00000dd0  64 72 25 21 31 32 3d 30  3a f4 20 52 65 73 65 72  |dr%!12=0:. Reser|
00000de0  76 65 64 0d 03 c0 3d 20  c8 99 20 22 58 53 6f 63  |ved...= .. "XSoc|
00000df0  6b 65 74 5f 42 69 6e 64  22 2c 73 6f 63 6b 25 28  |ket_Bind",sock%(|
00000e00  73 6f 63 6b 25 29 21 30  2c 73 6f 63 6b 61 64 64  |sock%)!0,sockadd|
00000e10  72 25 2c 31 36 20 b8 72  30 3b 66 6c 61 67 73 25  |r%,16 .r0;flags%|
00000e20  0d 03 ca 28 20 e7 20 28  66 6c 61 67 73 25 20 80  |...( . (flags% .|
00000e30  31 29 3d 31 20 8c 70 6f  72 74 25 2b 3d 31 3a 6c  |1)=1 .port%+=1:l|
00000e40  69 6d 69 74 25 2d 3d 31  0d 03 d4 1e fd 20 28 66  |imit%-=1..... (f|
00000e50  6c 61 67 73 25 20 80 31  29 3d 30 20 84 20 6c 69  |lags% .1)=0 . li|
00000e60  6d 69 74 25 3c 30 0d 03  de 13 e7 20 6c 69 6d 69  |mit%<0..... limi|
00000e70  74 25 3c 30 20 8c 3d 2d  31 0d 03 e8 23 f4 20 4d  |t%<0 .=-1...#. M|
00000e80  61 72 6b 20 61 73 20 61  20 6e 6f 6e 2d 62 6c 6f  |ark as a non-blo|
00000e90  63 6b 69 6e 67 20 73 6f  63 6b 65 74 0d 03 f2 45  |cking socket...E|
00000ea0  21 73 6f 63 6b 74 65 6d  70 25 3d 2d 31 3a c8 99  |!socktemp%=-1:..|
00000eb0  20 22 58 53 6f 63 6b 65  74 5f 49 6f 63 74 6c 22  | "XSocket_Ioctl"|
00000ec0  2c 73 6f 63 6b 25 28 73  6f 63 6b 25 29 21 30 2c  |,sock%(sock%)!0,|
00000ed0  46 49 4f 4e 42 49 4f 2c  73 6f 63 6b 74 65 6d 70  |FIONBIO,socktemp|
00000ee0  25 0d 03 fc 14 f4 20 4d  61 6b 65 20 69 74 20 6c  |%..... Make it l|
00000ef0  69 73 74 65 6e 0d 04 06  3c c8 99 20 22 58 53 6f  |isten...<.. "XSo|
00000f00  63 6b 65 74 5f 4c 69 73  74 65 6e 22 2c 73 6f 63  |cket_Listen",soc|
00000f10  6b 25 28 73 6f 63 6b 25  29 21 30 2c 35 20 3a f4  |k%(sock%)!0,5 :.|
00000f20  20 35 20 69 73 20 74 68  65 20 62 61 63 6b 6c 6f  | 5 is the backlo|
00000f30  67 0d 04 10 2c f4 20 4d  61 72 6b 20 61 73 20 6c  |g...,. Mark as l|
00000f40  69 73 74 65 6e 69 6e 67  20 28 69 65 20 77 65 27  |istening (ie we'|
00000f50  72 65 20 61 6e 73 77 65  72 69 6e 67 29 0d 04 1a  |re answering)...|
00000f60  2f 73 6f 63 6b 25 28 73  6f 63 6b 25 29 21 26 43  |/sock%(sock%)!&C|
00000f70  3d 28 73 6f 63 6b 25 28  73 6f 63 6b 25 29 21 26  |=(sock%(sock%)!&|
00000f80  43 20 80 20 ac 20 31 29  20 84 20 31 0d 04 24 0a  |C . . 1) . 1..$.|
00000f90  3d 70 6f 72 74 25 0d 04  2e 05 3a 0d 04 38 31 f4  |=port%....:..81.|
00000fa0  20 46 4e 73 6f 63 6b 65  74 5f 63 6f 6e 6e 65 63  | FNsocket_connec|
00000fb0  74 20 3a 20 43 6f 6e 6e  65 63 74 20 74 6f 20 61  |t : Connect to a|
00000fc0  20 72 65 6d 6f 74 65 20  68 6f 73 74 0d 04 42 25  | remote host..B%|
00000fd0  dd a4 73 6f 63 6b 65 74  5f 63 6f 6e 6e 65 63 74  |..socket_connect|
00000fe0  28 73 6f 63 6b 25 2c 69  70 25 2c 70 6f 72 74 25  |(sock%,ip%,port%|
00000ff0  29 0d 04 4c 20 ea 66 6c  61 67 73 25 2c 72 30 3a  |)..L .flags%,r0:|
00001000  70 6f 72 74 25 3d 70 6f  72 74 25 80 26 46 46 46  |port%=port%.&FFF|
00001010  46 0d 04 56 22 f2 73 6f  63 6b 65 74 5f 63 68 65  |F..V".socket_che|
00001020  63 6b 28 73 6f 63 6b 25  2c 22 43 6f 6e 6e 65 63  |ck(sock%,"Connec|
00001030  74 22 29 0d 04 60 1d f4  20 41 46 5f 49 4e 45 54  |t")..`.. AF_INET|
00001040  20 61 6e 64 20 70 6f 72  74 20 6e 75 6d 62 65 72  | and port number|
00001050  0d 04 6a 3b 73 6f 63 6b  61 64 64 72 25 21 30 3d  |..j;sockaddr%!0=|
00001060  32 20 84 20 28 28 70 6f  72 74 25 20 81 32 35 36  |2 . ((port% .256|
00001070  29 3c 3c 31 36 29 20 84  20 28 28 70 6f 72 74 25  |)<<16) . ((port%|
00001080  20 83 32 35 36 29 3c 3c  32 34 29 0d 04 74 26 73  | .256)<<24)..t&s|
00001090  6f 63 6b 61 64 64 72 25  21 34 3d 69 70 25 3a f4  |ockaddr%!4=ip%:.|
000010a0  20 49 6e 20 72 65 76 65  72 73 65 20 6f 72 64 65  | In reverse orde|
000010b0  72 0d 04 7e 2b 73 6f 63  6b 61 64 64 72 25 21 38  |r..~+sockaddr%!8|
000010c0  3d 30 3a 73 6f 63 6b 61  64 64 72 25 21 31 32 3d  |=0:sockaddr%!12=|
000010d0  30 3a f4 20 52 65 73 65  72 76 65 64 0d 04 88 3f  |0:. Reserved...?|
000010e0  c8 99 20 22 58 53 6f 63  6b 65 74 5f 43 6f 6e 6e  |.. "XSocket_Conn|
000010f0  65 63 74 22 2c 73 6f 63  6b 25 28 73 6f 63 6b 25  |ect",sock%(sock%|
00001100  29 21 30 2c 73 6f 63 6b  61 64 64 72 25 2c 31 36  |)!0,sockaddr%,16|
00001110  20 b8 72 30 3b 66 6c 61  67 73 25 0d 04 92 17 e7  | .r0;flags%.....|
00001120  20 28 66 6c 61 67 73 25  20 80 31 29 3d 31 20 8c  | (flags% .1)=1 .|
00001130  3d a3 0d 04 9c 23 f4 20  4d 61 72 6b 20 61 73 20  |=....#. Mark as |
00001140  61 20 6e 6f 6e 2d 62 6c  6f 63 6b 69 6e 67 20 73  |a non-blocking s|
00001150  6f 63 6b 65 74 0d 04 a6  45 21 73 6f 63 6b 74 65  |ocket...E!sockte|
00001160  6d 70 25 3d 2d 31 3a c8  99 20 22 58 53 6f 63 6b  |mp%=-1:.. "XSock|
00001170  65 74 5f 49 6f 63 74 6c  22 2c 73 6f 63 6b 25 28  |et_Ioctl",sock%(|
00001180  73 6f 63 6b 25 29 21 30  2c 46 49 4f 4e 42 49 4f  |sock%)!0,FIONBIO|
00001190  2c 73 6f 63 6b 74 65 6d  70 25 0d 04 b0 35 f4 20  |,socktemp%...5. |
000011a0  4d 61 72 6b 20 61 73 20  74 61 6c 6b 69 6e 67 20  |Mark as talking |
000011b0  28 69 65 20 77 65 27 72  65 20 64 6f 69 6e 67 20  |(ie we're doing |
000011c0  74 68 65 20 63 6f 6e 6e  65 63 74 69 6e 67 29 0d  |the connecting).|
000011d0  04 ba 2b 73 6f 63 6b 25  28 73 6f 63 6b 25 29 21  |..+sock%(sock%)!|
000011e0  26 43 3d 28 73 6f 63 6b  25 28 73 6f 63 6b 25 29  |&C=(sock%(sock%)|
000011f0  21 26 43 20 80 20 ac 20  31 29 0d 04 c4 06 3d b9  |!&C . . 1)....=.|
00001200  0d 04 ce 05 3a 0d 04 d8  38 f4 20 46 4e 73 6f 63  |....:...8. FNsoc|
00001210  6b 65 74 5f 6e 6f 62 6c  6f 63 6b 63 6f 6e 6e 65  |ket_noblockconne|
00001220  63 74 20 3a 20 43 6f 6e  6e 65 63 74 20 77 69 74  |ct : Connect wit|
00001230  68 6f 75 74 20 62 6c 6f  63 6b 69 6e 67 0d 04 e2  |hout blocking...|
00001240  37 f4 20 52 65 74 75 72  6e 73 20 46 41 4c 53 45  |7. Returns FALSE|
00001250  20 69 66 20 63 6f 75 6c  64 6e 27 74 20 63 6f 6e  | if couldn't con|
00001260  6e 65 63 74 2c 20 54 52  55 45 20 69 66 20 69 74  |nect, TRUE if it|
00001270  20 64 69 64 0d 04 ec 2a  f4 20 61 6e 64 20 2d 54  | did...*. and -T|
00001280  52 55 45 20 69 66 20 69  74 20 69 73 20 63 75 72  |RUE if it is cur|
00001290  72 65 6e 74 6c 79 20 74  72 79 69 6e 67 2e 0d 04  |rently trying...|
000012a0  f6 2c dd a4 73 6f 63 6b  65 74 5f 6e 6f 62 6c 6f  |.,..socket_noblo|
000012b0  63 6b 63 6f 6e 6e 65 63  74 28 73 6f 63 6b 25 2c  |ckconnect(sock%,|
000012c0  69 70 25 2c 70 6f 72 74  25 29 0d 05 00 25 ea 66  |ip%,port%)...%.f|
000012d0  6c 61 67 73 25 2c 72 30  2c 72 65 73 25 3a 70 6f  |lags%,r0,res%:po|
000012e0  72 74 25 3d 70 6f 72 74  25 80 26 46 46 46 46 0d  |rt%=port%.&FFFF.|
000012f0  05 0a 22 f2 73 6f 63 6b  65 74 5f 63 68 65 63 6b  |..".socket_check|
00001300  28 73 6f 63 6b 25 2c 22  43 6f 6e 6e 65 63 74 22  |(sock%,"Connect"|
00001310  29 0d 05 14 23 f4 20 4d  61 72 6b 20 61 73 20 61  |)...#. Mark as a|
00001320  20 6e 6f 6e 2d 62 6c 6f  63 6b 69 6e 67 20 73 6f  | non-blocking so|
00001330  63 6b 65 74 0d 05 1e 45  21 73 6f 63 6b 74 65 6d  |cket...E!socktem|
00001340  70 25 3d 2d 31 3a c8 99  20 22 58 53 6f 63 6b 65  |p%=-1:.. "XSocke|
00001350  74 5f 49 6f 63 74 6c 22  2c 73 6f 63 6b 25 28 73  |t_Ioctl",sock%(s|
00001360  6f 63 6b 25 29 21 30 2c  46 49 4f 4e 42 49 4f 2c  |ock%)!0,FIONBIO,|
00001370  73 6f 63 6b 74 65 6d 70  25 0d 05 28 1d f4 20 41  |socktemp%..(.. A|
00001380  46 5f 49 4e 45 54 20 61  6e 64 20 70 6f 72 74 20  |F_INET and port |
00001390  6e 75 6d 62 65 72 0d 05  32 3b 73 6f 63 6b 61 64  |number..2;sockad|
000013a0  64 72 25 21 30 3d 32 20  84 20 28 28 70 6f 72 74  |dr%!0=2 . ((port|
000013b0  25 20 81 32 35 36 29 3c  3c 31 36 29 20 84 20 28  |% .256)<<16) . (|
000013c0  28 70 6f 72 74 25 20 83  32 35 36 29 3c 3c 32 34  |(port% .256)<<24|
000013d0  29 0d 05 3c 26 73 6f 63  6b 61 64 64 72 25 21 34  |)..<&sockaddr%!4|
000013e0  3d 69 70 25 3a f4 20 49  6e 20 72 65 76 65 72 73  |=ip%:. In revers|
000013f0  65 20 6f 72 64 65 72 0d  05 46 2b 73 6f 63 6b 61  |e order..F+socka|
00001400  64 64 72 25 21 38 3d 30  3a 73 6f 63 6b 61 64 64  |ddr%!8=0:sockadd|
00001410  72 25 21 31 32 3d 30 3a  f4 20 52 65 73 65 72 76  |r%!12=0:. Reserv|
00001420  65 64 0d 05 50 3f c8 99  20 22 58 53 6f 63 6b 65  |ed..P?.. "XSocke|
00001430  74 5f 43 6f 6e 6e 65 63  74 22 2c 73 6f 63 6b 25  |t_Connect",sock%|
00001440  28 73 6f 63 6b 25 29 21  30 2c 73 6f 63 6b 61 64  |(sock%)!0,sockad|
00001450  64 72 25 2c 31 36 20 b8  72 30 3b 66 6c 61 67 73  |dr%,16 .r0;flags|
00001460  25 0d 05 5a 15 e7 20 28  66 6c 61 67 73 25 20 80  |%..Z.. (flags% .|
00001470  31 29 3d 31 20 8c 0d 05  64 27 20 f4 20 43 68 65  |1)=1 ...d' . Che|
00001480  63 6b 20 66 6f 72 20 65  72 72 6f 72 20 45 49 4e  |ck for error EIN|
00001490  50 52 4f 47 52 45 53 53  20 28 33 36 29 0d 05 6e  |PROGRESS (36)..n|
000014a0  19 20 e7 20 21 72 30 3d  33 36 20 8c 72 65 73 25  |. . !r0=36 .res%|
000014b0  3d 31 20 8b 3d a3 0d 05  78 05 cc 0d 05 82 27 20  |=1 .=...x.....' |
000014c0  f4 20 4f 74 68 65 72 77  69 73 65 20 69 74 27 73  |. Otherwise it's|
000014d0  20 63 6f 6e 6e 65 63 74  65 64 20 61 6c 72 65 61  | connected alrea|
000014e0  64 79 0d 05 8c 0b 20 72  65 73 25 3d b9 0d 05 96  |dy.... res%=....|
000014f0  05 cd 0d 05 a0 2d f4 20  4d 61 72 6b 20 61 73 20  |.....-. Mark as |
00001500  74 61 6c 6b 69 6e 67 2c  20 61 6e 64 20 77 65 27  |talking, and we'|
00001510  72 65 20 6e 6f 6e 2d 62  6c 6f 63 6b 69 6e 67 0d  |re non-blocking.|
00001520  05 aa 2f 73 6f 63 6b 25  28 73 6f 63 6b 25 29 21  |../sock%(sock%)!|
00001530  26 43 3d 28 73 6f 63 6b  25 28 73 6f 63 6b 25 29  |&C=(sock%(sock%)|
00001540  21 26 43 20 80 20 ac 20  31 29 20 84 20 34 0d 05  |!&C . . 1) . 4..|
00001550  b4 09 3d 72 65 73 25 0d  05 be 05 3a 0d 05 c8 2b  |..=res%....:...+|
00001560  f4 20 46 4e 73 6f 63 6b  65 74 5f 61 63 63 65 70  |. FNsocket_accep|
00001570  74 20 3a 20 41 63 63 65  70 74 20 61 20 63 6f 6e  |t : Accept a con|
00001580  6e 65 63 74 69 6f 6e 0d  05 d2 1a dd a4 73 6f 63  |nection......soc|
00001590  6b 65 74 5f 61 63 63 65  70 74 28 6d 61 69 6e 25  |ket_accept(main%|
000015a0  29 0d 05 dc 21 f2 73 6f  63 6b 65 74 5f 63 68 65  |)...!.socket_che|
000015b0  63 6b 28 6d 61 69 6e 25  2c 22 41 63 63 65 70 74  |ck(main%,"Accept|
000015c0  22 29 0d 05 e6 2b ea 20  73 6b 74 25 2c 73 6f 63  |")...+. skt%,soc|
000015d0  6b 25 2c 4f 3a 73 6f 63  6b 25 3d a4 73 6f 63 6b  |k%,O:sock%=.sock|
000015e0  65 74 5f 66 69 6e 64 68  61 6e 64 6c 65 0d 05 f0  |et_findhandle...|
000015f0  13 e7 20 73 6f 63 6b 25  3d 2d 31 20 8c 3d 2d 31  |.. sock%=-1 .=-1|
00001600  0d 05 fa 11 21 73 6f 63  6b 74 65 6d 70 25 3d 31  |....!socktemp%=1|
00001610  36 0d 06 04 48 c8 99 20  22 58 53 6f 63 6b 65 74  |6...H.. "XSocket|
00001620  5f 41 63 63 65 70 74 22  2c 73 6f 63 6b 25 28 6d  |_Accept",sock%(m|
00001630  61 69 6e 25 29 21 30 2c  73 6f 63 6b 61 64 64 72  |ain%)!0,sockaddr|
00001640  25 2c 73 6f 63 6b 74 65  6d 70 25 20 b8 20 73 6b  |%,socktemp% . sk|
00001650  74 25 3b 66 6c 61 67 73  25 0d 06 0e 3a e7 20 28  |t%;flags%...:. (|
00001660  66 6c 61 67 73 25 20 80  20 31 29 3d 31 20 84 20  |flags% . 1)=1 . |
00001670  73 6b 74 25 3d 2d 31 20  8c f2 72 65 6c 65 61 73  |skt%=-1 ..releas|
00001680  65 28 73 6f 63 6b 25 28  73 6f 63 6b 25 29 29 3a  |e(sock%(sock%)):|
00001690  3d 2d 31 0d 06 18 17 73  6f 63 6b 25 28 73 6f 63  |=-1....sock%(soc|
000016a0  6b 25 29 21 30 3d 73 6b  74 25 0d 06 22 1b f4 20  |k%)!0=skt%..".. |
000016b0  43 6f 70 79 20 74 68 65  20 73 6f 63 6b 65 74 20  |Copy the socket |
000016c0  62 6c 6f 63 6b 0d 06 2c  39 e3 4f 3d 34 b8 20 73  |block..,9.O=4. s|
000016d0  6f 63 6b 73 69 7a 65 25  2d 34 20 88 20 34 3a 73  |ocksize%-4 . 4:s|
000016e0  6f 63 6b 25 28 73 6f 63  6b 25 29 21 4f 3d 73 6f  |ock%(sock%)!O=so|
000016f0  63 6b 25 28 6d 61 69 6e  25 29 21 4f 3a ed 0d 06  |ck%(main%)!O:...|
00001700  36 3e f4 20 49 66 20 69  74 20 69 73 20 61 20 62  |6>. If it is a b|
00001710  75 66 66 65 72 65 64 20  73 6f 63 6b 65 74 20 74  |uffered socket t|
00001720  68 65 6e 20 63 6c 61 69  6d 20 73 6f 6d 65 20 6d  |hen claim some m|
00001730  65 6d 6f 72 79 20 66 6f  72 20 69 74 0d 06 40 21  |emory for it..@!|
00001740  e7 20 28 28 73 6f 63 6b  25 28 6d 61 69 6e 25 29  |. ((sock%(main%)|
00001750  21 26 43 29 20 80 20 32  29 3d 32 20 8c 0d 06 4a  |!&C) . 2)=2 ...J|
00001760  27 20 73 6f 63 6b 25 28  73 6f 63 6b 25 29 21 34  |' sock%(sock%)!4|
00001770  3d a4 63 6c 61 69 6d 28  73 6f 63 6b 62 75 66 6c  |=.claim(sockbufl|
00001780  65 6e 25 29 0d 06 54 19  20 e7 20 73 6f 63 6b 25  |en%)..T. . sock%|
00001790  28 73 6f 63 6b 25 29 21  34 3c 30 20 8c 0d 06 5e  |(sock%)!4<0 ...^|
000017a0  22 20 20 f4 20 4e 6f 74  20 65 6e 6f 75 67 68 20  |"  . Not enough |
000017b0  6d 65 6d 6f 72 79 20 74  6f 20 63 6c 61 69 6d 0d  |memory to claim.|
000017c0  06 68 1c 20 20 f2 72 65  6c 65 61 73 65 28 73 6f  |.h.  .release(so|
000017d0  63 6b 25 28 73 6f 63 6b  25 29 29 0d 06 72 09 20  |ck%(sock%))..r. |
000017e0  20 3d 2d 31 0d 06 7c 06  20 cd 0d 06 86 2a 20 73  | =-1..|. ....* s|
000017f0  6f 63 6b 25 28 73 6f 63  6b 25 29 21 38 3d 30 3a  |ock%(sock%)!8=0:|
00001800  f4 20 4e 6f 20 62 79 74  65 73 20 69 6e 20 62 75  |. No bytes in bu|
00001810  66 66 65 72 0d 06 90 05  cd 0d 06 9a 0a 3d 73 6f  |ffer.........=so|
00001820  63 6b 25 0d 06 a4 05 3a  0d 06 ae 1a f4 20 2a 2a  |ck%....:..... **|
00001830  2a 2a 2a 2a 2a 2a 20 4e  4f 54 45 20 2a 2a 2a 2a  |****** NOTE ****|
00001840  2a 2a 0d 06 b8 40 f4 20  54 77 6f 20 63 61 6c 6c  |**...@. Two call|
00001850  73 20 6e 6f 74 20 69 6e  63 6c 75 64 65 64 20 69  |s not included i|
00001860  6e 20 74 68 65 20 53 48  20 6d 61 6e 75 61 6c 20  |n the SH manual |
00001870  6f 72 20 64 69 73 74 72  69 62 75 74 65 64 20 79  |or distributed y|
00001880  65 74 0d 06 c2 41 f4 20  50 52 4f 43 73 6f 63 6b  |et...A. PROCsock|
00001890  65 74 5f 72 65 63 76 62  75 66 66 65 72 20 3a 20  |et_recvbuffer : |
000018a0  53 65 74 73 20 74 68 65  20 73 69 7a 65 20 6f 66  |Sets the size of|
000018b0  20 74 68 65 20 72 65 63  65 69 76 65 20 62 75 66  | the receive buf|
000018c0  66 65 72 0d 06 cc 29 dd  f2 73 6f 63 6b 65 74 5f  |fer...)..socket_|
000018d0  72 65 63 76 62 75 66 66  65 72 28 73 6f 63 6b 25  |recvbuffer(sock%|
000018e0  2c 21 73 6f 63 6b 74 65  6d 70 25 29 0d 06 d6 25  |,!socktemp%)...%|
000018f0  f2 73 6f 63 6b 65 74 5f  63 68 65 63 6b 28 73 6f  |.socket_check(so|
00001900  63 6b 25 2c 22 52 65 63  76 42 75 66 66 65 72 22  |ck%,"RecvBuffer"|
00001910  29 0d 06 e0 45 c8 99 20  22 53 6f 63 6b 65 74 5f  |)...E.. "Socket_|
00001920  53 65 74 73 6f 63 6b 6f  70 74 22 2c 73 6f 63 6b  |Setsockopt",sock|
00001930  25 28 73 6f 63 6b 25 29  21 30 2c 26 46 46 46 46  |%(sock%)!0,&FFFF|
00001940  2c 53 4f 5f 52 43 56 42  55 46 2c 73 6f 63 6b 74  |,SO_RCVBUF,sockt|
00001950  65 6d 70 25 2c 34 0d 06  ea 05 e1 0d 06 f4 05 3a  |emp%,4.........:|
00001960  0d 06 fe 3e f4 20 50 52  4f 43 73 6f 63 6b 65 74  |...>. PROCsocket|
00001970  5f 73 65 6e 64 62 75 66  66 65 72 20 3a 20 53 65  |_sendbuffer : Se|
00001980  74 73 20 74 68 65 20 73  69 7a 65 20 6f 66 20 74  |ts the size of t|
00001990  68 65 20 73 65 6e 64 20  62 75 66 66 65 72 0d 07  |he send buffer..|
000019a0  08 29 dd f2 73 6f 63 6b  65 74 5f 73 65 6e 64 62  |.)..socket_sendb|
000019b0  75 66 66 65 72 28 73 6f  63 6b 25 2c 21 73 6f 63  |uffer(sock%,!soc|
000019c0  6b 74 65 6d 70 25 29 0d  07 12 25 f2 73 6f 63 6b  |ktemp%)...%.sock|
000019d0  65 74 5f 63 68 65 63 6b  28 73 6f 63 6b 25 2c 22  |et_check(sock%,"|
000019e0  52 65 63 76 42 75 66 66  65 72 22 29 0d 07 1c 45  |RecvBuffer")...E|
000019f0  c8 99 20 22 53 6f 63 6b  65 74 5f 53 65 74 73 6f  |.. "Socket_Setso|
00001a00  63 6b 6f 70 74 22 2c 73  6f 63 6b 25 28 73 6f 63  |ckopt",sock%(soc|
00001a10  6b 25 29 21 30 2c 26 46  46 46 46 2c 53 4f 5f 53  |k%)!0,&FFFF,SO_S|
00001a20  4e 44 42 55 46 2c 73 6f  63 6b 74 65 6d 70 25 2c  |NDBUF,socktemp%,|
00001a30  34 0d 07 26 05 e1 0d 07  30 05 3a 0d 07 3a 41 f4  |4..&....0.:..:A.|
00001a40  20 50 52 4f 43 73 6f 63  6b 65 74 5f 6d 61 6b 65  | PROCsocket_make|
00001a50  62 75 66 66 65 72 65 64  20 3a 20 45 6e 73 75 72  |buffered : Ensur|
00001a60  65 73 20 74 68 61 74 20  61 20 73 6f 63 6b 65 74  |es that a socket|
00001a70  20 69 73 20 62 75 66 66  65 72 65 64 0d 07 44 20  | is buffered..D |
00001a80  dd f2 73 6f 63 6b 65 74  5f 6d 61 6b 65 62 75 66  |..socket_makebuf|
00001a90  66 65 72 65 64 28 73 6f  63 6b 25 29 0d 07 4e 27  |fered(sock%)..N'|
00001aa0  f2 73 6f 63 6b 65 74 5f  63 68 65 63 6b 28 73 6f  |.socket_check(so|
00001ab0  63 6b 25 2c 22 4d 61 6b  65 42 75 66 66 65 72 65  |ck%,"MakeBuffere|
00001ac0  64 22 29 0d 07 58 22 e7  20 28 28 73 6f 63 6b 25  |d")..X". ((sock%|
00001ad0  28 73 6f 63 6b 25 29 21  26 43 29 20 80 20 32 29  |(sock%)!&C) . 2)|
00001ae0  3d 32 20 8c e1 0d 07 62  26 73 6f 63 6b 25 28 73  |=2 ....b&sock%(s|
00001af0  6f 63 6b 25 29 21 34 3d  a4 63 6c 61 69 6d 28 73  |ock%)!4=.claim(s|
00001b00  6f 63 6b 62 75 66 6c 65  6e 25 29 0d 07 6c 50 e7  |ockbuflen%)..lP.|
00001b10  20 73 6f 63 6b 25 28 73  6f 63 6b 25 29 21 34 3c  | sock%(sock%)!4<|
00001b20  30 20 8c 85 20 73 6f 63  6b 65 72 72 25 2c 22 4d  |0 .. sockerr%,"M|
00001b30  61 6b 65 42 75 66 66 65  72 65 64 3a 20 43 6f 75  |akeBuffered: Cou|
00001b40  6c 64 20 6e 6f 74 20 63  6c 61 69 6d 20 65 6e 6f  |ld not claim eno|
00001b50  75 67 68 20 6d 65 6d 6f  72 79 22 0d 07 76 29 73  |ugh memory"..v)s|
00001b60  6f 63 6b 25 28 73 6f 63  6b 25 29 21 38 3d 30 3a  |ock%(sock%)!8=0:|
00001b70  f4 20 4e 6f 20 62 79 74  65 73 20 69 6e 20 62 75  |. No bytes in bu|
00001b80  66 66 65 72 0d 07 80 29  73 6f 63 6b 25 28 73 6f  |ffer...)sock%(so|
00001b90  63 6b 25 29 21 26 43 3d  28 73 6f 63 6b 25 28 73  |ck%)!&C=(sock%(s|
00001ba0  6f 63 6b 25 29 21 26 43  29 20 84 20 32 0d 07 8a  |ock%)!&C) . 2...|
00001bb0  05 e1 0d 07 94 05 3a 0d  07 9e 3f f4 20 50 52 4f  |......:...?. PRO|
00001bc0  43 73 6f 63 6b 65 74 5f  6d 61 6b 65 6c 69 6e 67  |Csocket_makeling|
00001bd0  65 72 20 3a 20 53 6f 63  6b 65 74 20 77 69 6c 6c  |er : Socket will|
00001be0  20 28 6e 6f 74 29 20 6c  69 6e 67 65 72 20 6f 6e  | (not) linger on|
00001bf0  20 63 6c 6f 73 65 0d 07  a8 24 dd f2 73 6f 63 6b  | close...$..sock|
00001c00  65 74 5f 6d 61 6b 65 6c  69 6e 67 65 72 28 73 6f  |et_makelinger(so|
00001c10  63 6b 25 2c 74 69 6d 65  25 29 0d 07 b2 25 f2 73  |ck%,time%)...%.s|
00001c20  6f 63 6b 65 74 5f 63 68  65 63 6b 28 73 6f 63 6b  |ocket_check(sock|
00001c30  25 2c 22 4d 61 6b 65 4c  69 6e 67 65 72 22 29 0d  |%,"MakeLinger").|
00001c40  07 bc 2d 73 6f 63 6b 74  65 6d 70 25 21 30 3d 31  |..-socktemp%!0=1|
00001c50  2b 28 74 69 6d 65 25 3d  30 29 3a 73 6f 63 6b 74  |+(time%=0):sockt|
00001c60  65 6d 70 25 21 34 3d 74  69 6d 65 25 0d 07 c6 40  |emp%!4=time%...@|
00001c70  c8 99 20 22 58 53 6f 63  6b 65 74 5f 53 65 74 73  |.. "XSocket_Sets|
00001c80  6f 63 6b 6f 70 74 22 2c  73 6f 63 6b 25 28 73 6f  |ockopt",sock%(so|
00001c90  63 6b 25 29 21 30 2c 26  46 46 46 46 2c 26 38 30  |ck%)!0,&FFFF,&80|
00001ca0  2c 73 6f 63 6b 74 65 6d  70 25 2c 38 0d 07 d0 05  |,socktemp%,8....|
00001cb0  e1 0d 07 da 05 3a 0d 07  e4 40 f4 20 50 52 4f 43  |.....:...@. PROC|
00001cc0  73 6f 63 6b 65 74 5f 6d  61 6b 65 72 65 75 73 61  |socket_makereusa|
00001cd0  62 6c 65 20 3a 20 53 6f  63 6b 65 74 20 63 61 6e  |ble : Socket can|
00001ce0  20 62 65 20 72 65 75 73  65 64 20 77 68 65 6e 20  | be reused when |
00001cf0  63 6c 6f 73 65 64 0d 07  ee 26 dd f2 73 6f 63 6b  |closed...&..sock|
00001d00  65 74 5f 6d 61 6b 65 72  65 75 73 61 62 6c 65 28  |et_makereusable(|
00001d10  73 6f 63 6b 25 2c 66 6c  61 67 25 29 0d 07 f8 27  |sock%,flag%)...'|
00001d20  f2 73 6f 63 6b 65 74 5f  63 68 65 63 6b 28 73 6f  |.socket_check(so|
00001d30  63 6b 25 2c 22 4d 61 6b  65 52 65 75 73 61 62 6c  |ck%,"MakeReusabl|
00001d40  65 22 29 0d 08 02 1b 73  6f 63 6b 74 65 6d 70 25  |e")....socktemp%|
00001d50  21 30 3d 2d 28 66 6c 61  67 25 3c 3e 30 29 0d 08  |!0=-(flag%<>0)..|
00001d60  0c 3f c8 99 20 22 58 53  6f 63 6b 65 74 5f 53 65  |.?.. "XSocket_Se|
00001d70  74 73 6f 63 6b 6f 70 74  22 2c 73 6f 63 6b 25 28  |tsockopt",sock%(|
00001d80  73 6f 63 6b 25 29 21 30  2c 26 46 46 46 46 2c 26  |sock%)!0,&FFFF,&|
00001d90  34 2c 73 6f 63 6b 74 65  6d 70 25 2c 34 0d 08 16  |4,socktemp%,4...|
00001da0  41 c8 99 20 22 58 53 6f  63 6b 65 74 5f 53 65 74  |A.. "XSocket_Set|
00001db0  73 6f 63 6b 6f 70 74 22  2c 73 6f 63 6b 25 28 73  |sockopt",sock%(s|
00001dc0  6f 63 6b 25 29 21 30 2c  26 46 46 46 46 2c 26 32  |ock%)!0,&FFFF,&2|
00001dd0  30 30 2c 73 6f 63 6b 74  65 6d 70 25 2c 34 0d 08  |00,socktemp%,4..|
00001de0  20 05 e1 0d 08 2a 05 3a  0d 08 34 3e f4 20 50 52  | ....*.:..4>. PR|
00001df0  4f 43 63 6c 6f 73 65 73  6f 63 6b 65 74 73 20 3a  |OCclosesockets :|
00001e00  20 4b 69 6c 6c 20 61 6c  6c 20 61 63 74 69 76 65  | Kill all active|
00001e10  20 73 6f 63 6b 65 74 73  20 61 6e 64 20 63 6c 6f  | sockets and clo|
00001e20  73 65 64 6f 77 6e 0d 08  3e 12 dd f2 63 6c 6f 73  |sedown..>...clos|
00001e30  65 73 6f 63 6b 65 74 73  0d 08 48 0b ea 20 49 25  |esockets..H.. I%|
00001e40  2c 73 25 0d 08 52 27 e3  49 25 3d 30 b8 32 35 36  |,s%..R'.I%=0.256|
00001e50  3a 73 25 3d 49 25 3a f2  73 6f 63 6b 65 74 5f 63  |:s%=I%:.socket_c|
00001e60  6c 6f 73 65 28 73 25 29  3a ed 0d 08 5c 17 f2 72  |lose(s%):...\..r|
00001e70  65 6c 65 61 73 65 28 73  6f 63 6b 6c 69 6e 65 25  |elease(sockline%|
00001e80  29 0d 08 66 30 c8 95 20  6d 74 63 68 61 69 6e 25  |)..f0.. mtchain%|
00001e90  3c 3e 30 3a f2 69 6e 65  74 5f 6b 69 6c 6c 6d 74  |<>0:.inet_killmt|
00001ea0  71 75 65 72 79 28 6d 74  63 68 61 69 6e 25 29 3a  |query(mtchain%):|
00001eb0  ce 0d 08 70 05 e1 0d 08  7a 05 3a 0d 08 84 2c f4  |...p....z.:...,.|
00001ec0  20 50 52 4f 43 73 6f 63  6b 65 74 5f 63 6c 6f 73  | PROCsocket_clos|
00001ed0  65 20 3a 20 43 6c 6f 73  65 20 61 20 73 6f 63 6b  |e : Close a sock|
00001ee0  65 74 20 64 6f 77 6e 0d  08 8e 1b dd f2 73 6f 63  |et down......soc|
00001ef0  6b 65 74 5f 63 6c 6f 73  65 28 f8 20 73 6f 63 6b  |ket_close(. sock|
00001f00  25 29 0d 08 98 1d e7 20  73 6f 63 6b 25 3e 3d 30  |%)..... sock%>=0|
00001f10  20 80 20 73 6f 63 6b 25  3c 3d 32 35 36 20 8c 0d  | . sock%<=256 ..|
00001f20  08 a2 18 20 e7 20 73 6f  63 6b 25 28 73 6f 63 6b  |... . sock%(sock|
00001f30  25 29 3e 2d 31 20 8c 0d  08 ac 2c 20 20 c8 99 20  |%)>-1 ....,  .. |
00001f40  22 58 53 6f 63 6b 65 74  5f 53 68 75 74 64 6f 77  |"XSocket_Shutdow|
00001f50  6e 22 2c 73 6f 63 6b 25  28 73 6f 63 6b 25 29 21  |n",sock%(sock%)!|
00001f60  30 2c 32 0d 08 b6 27 20  20 c8 99 20 22 58 53 6f  |0,2...'  .. "XSo|
00001f70  63 6b 65 74 5f 43 6c 6f  73 65 22 2c 73 6f 63 6b  |cket_Close",sock|
00001f80  25 28 73 6f 63 6b 25 29  21 30 0d 08 c0 3c 20 20  |%(sock%)!0...<  |
00001f90  e7 20 28 28 73 6f 63 6b  25 28 73 6f 63 6b 25 29  |. ((sock%(sock%)|
00001fa0  21 26 43 29 20 80 20 32  29 3d 32 20 8c f2 72 65  |!&C) . 2)=2 ..re|
00001fb0  6c 65 61 73 65 28 73 6f  63 6b 25 28 73 6f 63 6b  |lease(sock%(sock|
00001fc0  25 29 21 26 34 29 0d 08  ca 1c 20 20 f2 72 65 6c  |%)!&4)....  .rel|
00001fd0  65 61 73 65 28 73 6f 63  6b 25 28 73 6f 63 6b 25  |ease(sock%(sock%|
00001fe0  29 29 0d 08 d4 06 20 cd  0d 08 de 05 cd 0d 08 e8  |)).... .........|
00001ff0  0c 73 6f 63 6b 25 3d 2d  31 0d 08 f2 05 e1 0d 08  |.sock%=-1.......|
00002000  fc 05 3a 0d 09 06 3d f4  20 46 4e 73 6f 63 6b 65  |..:...=. FNsocke|
00002010  74 5f 69 6e 62 75 66 66  65 72 20 3a 20 52 65 61  |t_inbuffer : Rea|
00002020  64 20 61 6d 6f 75 6e 74  20 6f 66 20 64 61 74 61  |d amount of data|
00002030  20 69 6e 20 69 6e 70 75  74 20 62 75 66 66 65 72  | in input buffer|
00002040  0d 09 10 1c dd a4 73 6f  63 6b 65 74 5f 69 6e 62  |......socket_inb|
00002050  75 66 66 65 72 28 73 6f  63 6b 25 29 0d 09 1a 23  |uffer(sock%)...#|
00002060  f2 73 6f 63 6b 65 74 5f  63 68 65 63 6b 28 73 6f  |.socket_check(so|
00002070  63 6b 25 2c 22 49 6e 42  75 66 66 65 72 22 29 0d  |ck%,"InBuffer").|
00002080  09 24 38 c8 99 20 22 58  53 6f 63 6b 65 74 5f 49  |.$8.. "XSocket_I|
00002090  6f 63 74 6c 22 2c 73 6f  63 6b 25 28 73 6f 63 6b  |octl",sock%(sock|
000020a0  25 29 21 30 2c 46 49 4f  4e 52 45 41 44 2c 73 6f  |%)!0,FIONREAD,so|
000020b0  63 6b 74 65 6d 70 25 0d  09 2e 0f 3d 21 73 6f 63  |cktemp%....=!soc|
000020c0  6b 74 65 6d 70 25 0d 09  38 05 3a 0d 09 42 3c f4  |ktemp%..8.:..B<.|
000020d0  20 46 4e 73 6f 63 6b 65  74 5f 65 6f 66 20 3a 20  | FNsocket_eof : |
000020e0  52 65 74 75 72 6e 20 54  52 55 45 20 69 66 20 74  |Return TRUE if t|
000020f0  68 65 20 6f 74 68 65 72  20 65 6e 64 20 68 61 73  |he other end has|
00002100  20 63 6c 6f 73 65 64 0d  09 4c 17 dd a4 73 6f 63  | closed..L...soc|
00002110  6b 65 74 5f 65 6f 66 28  73 6f 63 6b 25 29 0d 09  |ket_eof(sock%)..|
00002120  56 1e f2 73 6f 63 6b 65  74 5f 63 68 65 63 6b 28  |V..socket_check(|
00002130  73 6f 63 6b 25 2c 22 45  6f 66 22 29 0d 09 60 25  |sock%,"Eof")..`%|
00002140  ea 20 6f 6b 2c 66 25 3a  6f 6b 3d a4 73 6f 63 6b  |. ok,f%:ok=.sock|
00002150  65 74 5f 72 65 61 64 79  28 73 6f 63 6b 25 2c b9  |et_ready(sock%,.|
00002160  29 0d 09 6a 0d e7 20 6f  6b 3c 3e 30 20 8c 0d 09  |)..j.. ok<>0 ...|
00002170  74 1e 20 f4 20 4d 53 47  5f 50 45 45 4b 20 2b 20  |t. . MSG_PEEK + |
00002180  4d 53 47 5f 44 4f 4e 54  57 41 49 54 0d 09 7e 40  |MSG_DONTWAIT..~@|
00002190  20 c8 99 20 22 58 53 6f  63 6b 65 74 5f 52 65 63  | .. "XSocket_Rec|
000021a0  76 22 2c 73 6f 63 6b 25  28 73 6f 63 6b 25 29 21  |v",sock%(sock%)!|
000021b0  30 2c 73 6f 63 6b 74 65  6d 70 25 2c 31 2c 26 32  |0,socktemp%,1,&2|
000021c0  2b 26 38 30 20 b8 20 6f  6b 3b 66 25 0d 09 88 1a  |+&80 . ok;f%....|
000021d0  20 6f 6b 3d 28 6f 6b 3d  30 29 20 84 20 28 66 25  | ok=(ok=0) . (f%|
000021e0  20 80 31 29 3d 31 0d 09  92 05 cd 0d 09 9c 07 3d  | .1)=1.........=|
000021f0  6f 6b 0d 09 a6 05 3a 0d  09 b0 37 f4 20 46 4e 73  |ok....:...7. FNs|
00002200  6f 63 6b 65 74 5f 72 65  61 64 79 20 3a 20 43 68  |ocket_ready : Ch|
00002210  65 63 6b 20 77 68 65 74  68 65 72 20 61 20 73 6f  |eck whether a so|
00002220  63 6b 65 74 20 69 73 20  75 73 61 62 6c 65 0d 09  |cket is usable..|
00002230  ba 1f dd a4 73 6f 63 6b  65 74 5f 72 65 61 64 79  |....socket_ready|
00002240  28 73 6f 63 6b 25 2c 72  65 61 64 25 29 0d 09 c4  |(sock%,read%)...|
00002250  20 f2 73 6f 63 6b 65 74  5f 63 68 65 63 6b 28 73  | .socket_check(s|
00002260  6f 63 6b 25 2c 22 52 65  61 64 79 22 29 0d 09 ce  |ock%,"Ready")...|
00002270  38 ea 20 49 2c 66 64 25  2c 62 25 2c 6f 6b 25 2c  |8. I,fd%,b%,ok%,|
00002280  72 25 2c 77 25 3a 66 64  25 3d 73 6f 63 6b 25 28  |r%,w%:fd%=sock%(|
00002290  73 6f 63 6b 25 29 21 30  3a 62 25 3d 73 6f 63 6b  |sock%)!0:b%=sock|
000022a0  74 65 6d 70 25 0d 09 d8  39 e3 20 49 3d 30 20 b8  |temp%...9. I=0 .|
000022b0  20 28 28 73 6f 63 6b 74  73 69 7a 65 25 2f 38 2b  | ((socktsize%/8+|
000022c0  33 29 20 80 20 ac 33 29  2d 31 20 88 20 34 3a 73  |3) . .3)-1 . 4:s|
000022d0  6f 63 6b 74 65 6d 70 25  21 49 3d 30 3a ed 0d 09  |ocktemp%!I=0:...|
000022e0  e2 31 c8 95 20 66 64 25  3e 3d 33 32 3a 62 25 2b  |.1.. fd%>=32:b%+|
000022f0  3d 34 3a 66 64 25 2d 3d  33 32 3a ce 3a 21 62 25  |=4:fd%-=32:.:!b%|
00002300  3d 21 62 25 20 84 20 28  31 3c 3c 66 64 25 29 0d  |=!b% . (1<<fd%).|
00002310  09 ec 32 62 25 3d 73 6f  63 6b 74 65 6d 70 25 2b  |..2b%=socktemp%+|
00002320  49 3a 21 62 25 3d 30 3a  62 25 21 34 3d 30 3a f4  |I:!b%=0:b%!4=0:.|
00002330  20 69 6d 6d 65 64 69 61  74 65 20 72 65 74 75 72  | immediate retur|
00002340  6e 0d 09 f6 27 e7 20 72  65 61 64 25 20 8c 72 25  |n...'. read% .r%|
00002350  3d 73 6f 63 6b 74 65 6d  70 25 20 8b 77 25 3d 73  |=socktemp% .w%=s|
00002360  6f 63 6b 74 65 6d 70 25  0d 0a 00 32 c8 99 20 22  |ocktemp%...2.. "|
00002370  53 6f 63 6b 65 74 5f 53  65 6c 65 63 74 22 2c 73  |Socket_Select",s|
00002380  6f 63 6b 74 73 69 7a 65  25 2c 72 25 2c 77 25 2c  |ocktsize%,r%,w%,|
00002390  30 2c 62 25 20 b8 20 6f  6b 25 0d 0a 0a 08 3d 6f  |0,b% . ok%....=o|
000023a0  6b 25 0d 0a 14 05 3a 0d  0a 1e 38 f4 20 46 4e 73  |k%....:...8. FNs|
000023b0  6f 63 6b 65 74 5f 63 6f  6e 6e 65 63 74 65 64 20  |ocket_connected |
000023c0  3a 20 43 68 65 63 6b 20  69 66 20 77 65 20 61 72  |: Check if we ar|
000023d0  65 20 63 6f 6e 6e 65 63  74 65 64 20 79 65 74 0d  |e connected yet.|
000023e0  0a 28 2c f4 20 54 52 55  45 20 69 66 20 77 65 20  |.(,. TRUE if we |
000023f0  61 72 65 2c 20 46 41 4c  53 45 20 69 66 20 77 6f  |are, FALSE if wo|
00002400  72 6b 69 6e 67 20 6f 6e  20 69 74 0d 0a 32 16 f4  |rking on it..2..|
00002410  20 65 72 72 6f 72 2c 20  6f 74 68 65 72 77 69 73  | error, otherwis|
00002420  65 0d 0a 3c 1d dd a4 73  6f 63 6b 65 74 5f 63 6f  |e..<...socket_co|
00002430  6e 6e 65 63 74 65 64 28  73 6f 63 6b 25 29 0d 0a  |nnected(sock%)..|
00002440  46 0b ea 20 6f 6b 2c 66  25 0d 0a 50 1d f4 20 4d  |F.. ok,f%..P.. M|
00002450  53 47 5f 50 45 45 4b 20  2b 20 4d 53 47 5f 44 4f  |SG_PEEK + MSG_DO|
00002460  4e 54 57 41 49 54 0d 0a  5a 3f c8 99 20 22 58 53  |NTWAIT..Z?.. "XS|
00002470  6f 63 6b 65 74 5f 52 65  63 76 22 2c 73 6f 63 6b  |ocket_Recv",sock|
00002480  25 28 73 6f 63 6b 25 29  21 30 2c 73 6f 63 6b 74  |%(sock%)!0,sockt|
00002490  65 6d 70 25 2c 31 2c 26  32 2b 26 38 30 20 b8 20  |emp%,1,&2+&80 . |
000024a0  6f 6b 3b 66 25 0d 0a 64  0f e7 20 28 66 25 20 80  |ok;f%..d.. (f% .|
000024b0  31 29 20 8c 0d 0a 6e 30  20 6f 6b 3d 21 6f 6b 3a  |1) ...n0 ok=!ok:|
000024c0  e7 20 6f 6b 3d 33 35 20  8c 6f 6b 3d b9 20 8b e7  |. ok=35 .ok=. ..|
000024d0  20 6f 6b 3d 33 36 20 84  20 6f 6b 3d 35 37 20 8c  | ok=36 . ok=57 .|
000024e0  6f 6b 3d a3 0d 0a 78 05  cc 0d 0a 82 09 20 6f 6b  |ok=...x...... ok|
000024f0  3d b9 0d 0a 8c 05 cd 0d  0a 96 07 3d 6f 6b 0d 0a  |=..........=ok..|
00002500  a0 05 3a 0d 0a aa 2f f4  20 46 4e 73 6f 63 6b 65  |..:.../. FNsocke|
00002510  74 5f 72 65 61 64 64 61  74 61 20 3a 20 52 65 61  |t_readdata : Rea|
00002520  64 20 64 61 74 61 20 69  6e 74 6f 20 62 75 66 66  |d data into buff|
00002530  65 72 0d 0a b4 25 dd a4  73 6f 63 6b 65 74 5f 72  |er...%..socket_r|
00002540  65 61 64 64 61 74 61 28  73 6f 63 6b 25 2c f8 20  |eaddata(sock%,. |
00002550  73 74 61 72 74 25 29 0d  0a be 13 ea 20 72 65 61  |start%)..... rea|
00002560  64 25 3a 72 65 61 64 25  3d 30 0d 0a c8 23 f2 73  |d%:read%=0...#.s|
00002570  6f 63 6b 65 74 5f 63 68  65 63 6b 28 73 6f 63 6b  |ocket_check(sock|
00002580  25 2c 22 52 65 61 64 44  61 74 61 22 29 0d 0a d2  |%,"ReadData")...|
00002590  44 f4 20 52 65 61 64 20  64 61 74 61 20 66 72 6f  |D. Read data fro|
000025a0  6d 20 73 6f 63 6b 65 74  20 74 6f 20 6f 75 72 20  |m socket to our |
000025b0  62 75 66 66 65 72 20 69  66 20 62 75 66 66 65 72  |buffer if buffer|
000025c0  65 64 2c 20 65 6c 73 65  20 74 6f 20 75 73 65 72  |ed, else to user|
000025d0  73 0d 0a dc 36 e7 20 28  28 73 6f 63 6b 25 28 73  |s...6. ((sock%(s|
000025e0  6f 63 6b 25 29 21 26 43  29 20 80 20 32 29 3d 32  |ock%)!&C) . 2)=2|
000025f0  20 8c 73 74 61 72 74 25  3d 73 6f 63 6b 25 28 73  | .start%=sock%(s|
00002600  6f 63 6b 25 29 21 34 0d  0a e6 79 e7 20 73 74 61  |ock%)!4...y. sta|
00002610  72 74 25 3c 26 38 30 30  30 20 8c 85 20 73 6f 63  |rt%<&8000 .. soc|
00002620  6b 65 72 72 25 2c 22 52  65 61 64 44 61 74 61 3a  |kerr%,"ReadData:|
00002630  20 53 74 75 70 69 64 20  61 64 64 72 65 73 73 20  | Stupid address |
00002640  66 6f 72 20 73 6f 63 6b  65 74 5f 72 65 61 64 64  |for socket_readd|
00002650  61 74 61 20 28 22 2b c3  7e 73 74 61 72 74 25 2b  |ata ("+.~start%+|
00002660  22 29 2c 20 66 6c 61 67  73 20 3d 20 22 2b c3 28  |"), flags = "+.(|
00002670  73 6f 63 6b 25 28 73 6f  63 6b 25 29 21 26 43 29  |sock%(sock%)!&C)|
00002680  0d 0a f0 21 e7 20 a4 73  6f 63 6b 65 74 5f 69 6e  |...!. .socket_in|
00002690  62 75 66 66 65 72 28 73  6f 63 6b 25 29 3e 30 20  |buffer(sock%)>0 |
000026a0  8c 0d 0a fa 3f 20 c8 99  20 22 53 6f 63 6b 65 74  |....? .. "Socket|
000026b0  5f 52 65 61 64 22 2c 73  6f 63 6b 25 28 73 6f 63  |_Read",sock%(soc|
000026c0  6b 25 29 21 30 2c 73 74  61 72 74 25 2c 73 6f 63  |k%)!0,start%,soc|
000026d0  6b 62 75 66 6c 65 6e 25  20 b8 20 72 65 61 64 25  |kbuflen% . read%|
000026e0  0d 0b 04 05 cd 0d 0b 0e  0a 3d 72 65 61 64 25 0d  |.........=read%.|
000026f0  0b 18 05 3a 0d 0b 22 3d  f4 20 46 4e 73 6f 63 6b  |...:.."=. FNsock|
00002700  65 74 5f 72 65 61 64 6c  69 6e 65 20 3a 20 52 65  |et_readline : Re|
00002710  61 64 20 61 20 6c 69 6e  65 20 69 6e 74 6f 20 61  |ad a line into a|
00002720  20 74 65 6d 70 6f 72 61  72 79 20 62 75 66 66 65  | temporary buffe|
00002730  72 0d 0b 2c 39 f4 20 4c  69 6e 65 20 77 69 6c 6c  |r..,9. Line will|
00002740  20 62 65 20 69 6e 20 61  20 74 65 6d 70 6f 72 61  | be in a tempora|
00002750  72 79 20 62 75 66 66 65  72 2c 20 74 65 72 6d 69  |ry buffer, termi|
00002760  6e 61 74 65 64 20 62 79  20 30 0d 0b 36 3f f4 20  |nated by 0..6?. |
00002770  2d 31 20 77 69 6c 6c 20  62 65 20 72 65 74 75 72  |-1 will be retur|
00002780  6e 65 64 20 69 66 20 6e  6f 20 63 6f 6d 70 6c 65  |ned if no comple|
00002790  74 65 20 6c 69 6e 65 20  68 61 73 20 62 65 65 6e  |te line has been|
000027a0  20 72 65 63 65 69 76 65  64 0d 0b 40 25 dd a4 73  | received..@%..s|
000027b0  6f 63 6b 65 74 5f 72 65  61 64 6c 69 6e 65 28 73  |ocket_readline(s|
000027c0  6f 63 6b 25 2c f8 20 73  74 61 72 74 25 29 0d 0b  |ock%,. start%)..|
000027d0  4a 1b ea 20 62 75 66 25  2c 6f 66 73 25 2c 49 25  |J.. buf%,ofs%,I%|
000027e0  2c 4f 25 2c 72 65 61 64  25 0d 0b 54 23 f2 73 6f  |,O%,read%..T#.so|
000027f0  63 6b 65 74 5f 63 68 65  63 6b 28 73 6f 63 6b 25  |cket_check(sock%|
00002800  2c 22 52 65 61 64 4c 69  6e 65 22 29 0d 0b 5e 5c  |,"ReadLine")..^\|
00002810  e7 20 28 73 6f 63 6b 25  28 73 6f 63 6b 25 29 21  |. (sock%(sock%)!|
00002820  26 43 20 80 20 32 29 3d  30 20 8c 85 20 73 6f 63  |&C . 2)=0 .. soc|
00002830  6b 65 72 72 25 2c 22 52  65 61 64 4c 69 6e 65 3a  |kerr%,"ReadLine:|
00002840  20 4e 6f 6e 2d 62 75 66  66 65 72 65 64 20 73 6f  | Non-buffered so|
00002850  63 6b 65 74 5f 72 65 61  64 6c 69 6e 65 20 61 74  |cket_readline at|
00002860  74 65 6d 70 74 65 64 22  0d 0b 68 0d 73 74 61 72  |tempted"..h.star|
00002870  74 25 3d 2d 31 0d 0b 72  29 f4 20 52 65 61 64 20  |t%=-1..r). Read |
00002880  64 61 74 61 20 66 72 6f  6d 20 73 6f 63 6b 65 74  |data from socket|
00002890  20 74 6f 20 6f 75 72 20  62 75 66 66 65 72 0d 0b  | to our buffer..|
000028a0  7c 2b 62 75 66 25 3d 73  6f 63 6b 25 28 73 6f 63  ||+buf%=sock%(soc|
000028b0  6b 25 29 21 34 3a 6f 66  73 25 3d 73 6f 63 6b 25  |k%)!4:ofs%=sock%|
000028c0  28 73 6f 63 6b 25 29 21  38 0d 0b 86 21 e7 20 a4  |(sock%)!8...!. .|
000028d0  73 6f 63 6b 65 74 5f 69  6e 62 75 66 66 65 72 28  |socket_inbuffer(|
000028e0  73 6f 63 6b 25 29 3e 30  20 8c 0d 0b 90 5b 20 e7  |sock%)>0 ....[ .|
000028f0  20 62 75 66 25 3c 26 38  30 30 30 20 8c 85 20 73  | buf%<&8000 .. s|
00002900  6f 63 6b 65 72 72 25 2c  22 52 65 61 64 4c 69 6e  |ockerr%,"ReadLin|
00002910  65 3a 20 53 74 75 70 69  64 20 61 64 64 72 65 73  |e: Stupid addres|
00002920  73 20 66 6f 72 20 73 6f  63 6b 65 74 5f 72 65 61  |s for socket_rea|
00002930  64 6c 69 6e 65 20 28 22  2b c3 7e 73 74 61 72 74  |dline ("+.~start|
00002940  25 2b 22 29 22 0d 0b 9a  47 20 c8 99 20 22 53 6f  |%+")"...G .. "So|
00002950  63 6b 65 74 5f 52 65 61  64 22 2c 73 6f 63 6b 25  |cket_Read",sock%|
00002960  28 73 6f 63 6b 25 29 21  30 2c 62 75 66 25 2b 6f  |(sock%)!0,buf%+o|
00002970  66 73 25 2c 73 6f 63 6b  62 75 66 6c 65 6e 25 2d  |fs%,sockbuflen%-|
00002980  6f 66 73 25 20 b8 20 72  65 61 64 25 0d 0b a4 45  |ofs% . read%...E|
00002990  20 e7 20 72 65 61 64 25  3c 31 20 8c 85 20 73 6f  | . read%<1 .. so|
000029a0  63 6b 65 72 72 25 2c 22  52 65 61 64 4c 69 6e 65  |ckerr%,"ReadLine|
000029b0  3a 20 44 69 64 6e 27 74  20 72 65 61 64 20 61 6e  |: Didn't read an|
000029c0  79 74 68 69 6e 67 20 3f  20 22 2b c3 72 65 61 64  |ything ? "+.read|
000029d0  25 0d 0b ae 14 20 6f 66  73 25 3d 6f 66 73 25 2b  |%.... ofs%=ofs%+|
000029e0  72 65 61 64 25 0d 0b b8  05 cd 0d 0b c2 11 e7 20  |read%.......... |
000029f0  6f 66 73 25 3d 30 20 8c  3d 2d 31 0d 0b cc 12 e3  |ofs%=0 .=-1.....|
00002a00  20 49 25 3d 30 b8 20 6f  66 73 25 2d 31 0d 0b d6  | I%=0. ofs%-1...|
00002a10  1c 20 e7 20 62 75 66 25  3f 49 25 3d 30 20 8c 62  |. . buf%?I%=0 .b|
00002a20  75 66 25 3f 49 25 3d 31  33 0d 0b e0 20 20 e7 20  |uf%?I%=13...  . |
00002a30  62 75 66 25 3f 49 25 3d  31 30 20 84 20 62 75 66  |buf%?I%=10 . buf|
00002a40  25 3f 49 25 3d 31 33 20  8c 0d 0b ea 29 20 20 f4  |%?I%=13 ....)  .|
00002a50  20 43 6f 70 79 20 6c 69  6e 65 20 74 6f 20 62 75  | Copy line to bu|
00002a60  66 66 65 72 20 61 6e 64  20 74 65 72 6d 69 6e 61  |ffer and termina|
00002a70  74 65 0d 0b f4 25 20 20  e3 4f 25 3d 30 b8 49 25  |te...%  .O%=0.I%|
00002a80  3a 73 6f 63 6b 6c 69 6e  65 25 3f 4f 25 3d 62 75  |:sockline%?O%=bu|
00002a90  66 25 3f 4f 25 3a ed 0d  0b fe 14 20 20 73 6f 63  |f%?O%:.....  soc|
00002aa0  6b 6c 69 6e 65 25 3f 49  25 3d 30 0d 0c 08 33 20  |kline%?I%=0...3 |
00002ab0  20 f4 20 43 6f 70 79 20  72 65 6d 61 69 6e 64 65  | . Copy remainde|
00002ac0  72 20 6f 66 20 62 75 66  66 65 72 20 74 6f 20 73  |r of buffer to s|
00002ad0  74 61 72 74 20 6f 66 20  62 75 66 66 65 72 0d 0c  |tart of buffer..|
00002ae0  12 30 20 20 e3 4f 25 3d  49 25 2b 31 20 b8 20 6f  |.0  .O%=I%+1 . o|
00002af0  66 73 25 2d 31 3a 62 75  66 25 3f 28 4f 25 2d 49  |fs%-1:buf%?(O%-I|
00002b00  25 2d 31 29 3d 62 75 66  25 3f 4f 25 3a ed 0d 0c  |%-1)=buf%?O%:...|
00002b10  1c 24 20 20 6f 66 73 25  2d 3d 49 25 2b 31 3a 73  |.$  ofs%-=I%+1:s|
00002b20  6f 63 6b 25 28 73 6f 63  6b 25 29 21 38 3d 6f 66  |ock%(sock%)!8=of|
00002b30  73 25 0d 0c 26 25 20 20  f4 20 52 65 74 75 72 6e  |s%..&%  . Return|
00002b40  20 77 69 74 68 20 62 75  66 66 65 72 20 61 6e 64  | with buffer and|
00002b50  20 6c 65 6e 67 74 68 0d  0c 30 1c 20 20 73 74 61  | length..0.  sta|
00002b60  72 74 25 3d 73 6f 63 6b  6c 69 6e 65 25 3a 3d 49  |rt%=sockline%:=I|
00002b70  25 2b 31 0d 0c 3a 06 20  cd 0d 0c 44 05 ed 0d 0c  |%+1..:. ...D....|
00002b80  4e 17 73 6f 63 6b 25 28  73 6f 63 6b 25 29 21 38  |N.sock%(sock%)!8|
00002b90  3d 6f 66 73 25 0d 0c 58  07 3d 2d 31 0d 0c 62 05  |=ofs%..X.=-1..b.|
00002ba0  3a 0d 0c 6c 35 f4 20 50  52 4f 43 73 6f 63 6b 65  |:..l5. PROCsocke|
00002bb0  74 5f 73 65 6e 64 6c 69  6e 65 20 3a 20 53 65 6e  |t_sendline : Sen|
00002bc0  64 20 61 20 73 74 72 69  6e 67 20 74 6f 20 61 20  |d a string to a |
00002bd0  73 6f 63 6b 65 74 0d 0c  76 1f dd f2 73 6f 63 6b  |socket..v...sock|
00002be0  65 74 5f 73 65 6e 64 6c  69 6e 65 28 73 6f 63 6b  |et_sendline(sock|
00002bf0  25 2c 6d 24 29 0d 0c 80  0f ea 20 72 30 2c 66 6c  |%,m$)..... r0,fl|
00002c00  61 67 73 25 0d 0c 8a 23  f2 73 6f 63 6b 65 74 5f  |ags%...#.socket_|
00002c10  63 68 65 63 6b 28 73 6f  63 6b 25 2c 22 53 65 6e  |check(sock%,"Sen|
00002c20  64 4c 69 6e 65 22 29 0d  0c 94 17 24 28 73 6f 63  |dLine")....$(soc|
00002c30  6b 74 65 6d 70 25 29 3d  6d 24 2b bd 31 30 0d 0c  |ktemp%)=m$+.10..|
00002c40  9e 42 c8 99 20 22 58 53  6f 63 6b 65 74 5f 57 72  |.B.. "XSocket_Wr|
00002c50  69 74 65 22 2c 73 6f 63  6b 25 28 73 6f 63 6b 25  |ite",sock%(sock%|
00002c60  29 21 30 2c 73 6f 63 6b  74 65 6d 70 25 2c a9 28  |)!0,socktemp%,.(|
00002c70  6d 24 29 2b 31 20 b8 72  30 3b 66 6c 61 67 73 25  |m$)+1 .r0;flags%|
00002c80  0d 0c a8 46 f4 20 49 46  20 28 66 6c 61 67 73 25  |...F. IF (flags%|
00002c90  20 41 4e 44 20 31 29 3d  31 20 54 48 45 4e 45 52  | AND 1)=1 THENER|
00002ca0  52 4f 52 20 73 6f 63 6b  65 72 72 25 2c 22 57 72  |ROR sockerr%,"Wr|
00002cb0  69 74 65 3a 20 22 2b 46  4e 73 74 72 69 6e 67 30  |ite: "+FNstring0|
00002cc0  28 72 30 2b 34 29 0d 0c  b2 37 e7 20 72 30 3c 3e  |(r0+4)...7. r0<>|
00002cd0  a9 28 6d 24 29 2b 31 20  8c 85 20 73 6f 63 6b 65  |.(m$)+1 .. socke|
00002ce0  72 72 25 2c 22 43 6f 75  6c 64 20 6e 6f 74 20 73  |rr%,"Could not s|
00002cf0  65 6e 64 20 61 6c 6c 20  64 61 74 61 22 0d 0c bc  |end all data"...|
00002d00  05 e1 0d 0c c6 05 3a 0d  0c d0 31 f4 20 50 52 4f  |......:...1. PRO|
00002d10  43 73 6f 63 6b 65 74 5f  73 65 6e 64 64 61 74 61  |Csocket_senddata|
00002d20  20 3a 20 53 65 6e 64 20  64 61 74 61 20 74 6f 20  | : Send data to |
00002d30  61 20 73 6f 63 6b 65 74  0d 0c da 24 dd f2 73 6f  |a socket...$..so|
00002d40  63 6b 65 74 5f 73 65 6e  64 64 61 74 61 28 73 6f  |cket_senddata(so|
00002d50  63 6b 25 2c 62 25 2c 6c  65 6e 25 29 0d 0c e4 0f  |ck%,b%,len%)....|
00002d60  ea 20 72 30 2c 66 6c 61  67 73 25 0d 0c ee 23 f2  |. r0,flags%...#.|
00002d70  73 6f 63 6b 65 74 5f 63  68 65 63 6b 28 73 6f 63  |socket_check(soc|
00002d80  6b 25 2c 22 53 65 6e 64  44 61 74 61 22 29 0d 0c  |k%,"SendData")..|
00002d90  f8 38 c8 99 20 22 58 53  6f 63 6b 65 74 5f 57 72  |.8.. "XSocket_Wr|
00002da0  69 74 65 22 2c 73 6f 63  6b 25 28 73 6f 63 6b 25  |ite",sock%(sock%|
00002db0  29 21 30 2c 62 25 2c 6c  65 6e 25 20 b8 72 30 3b  |)!0,b%,len% .r0;|
00002dc0  66 6c 61 67 73 25 0d 0d  02 46 f4 20 49 46 20 28  |flags%...F. IF (|
00002dd0  66 6c 61 67 73 25 20 41  4e 44 20 31 29 3d 31 20  |flags% AND 1)=1 |
00002de0  54 48 45 4e 45 52 52 4f  52 20 73 6f 63 6b 65 72  |THENERROR socker|
00002df0  72 25 2c 22 57 72 69 74  65 3a 20 22 2b 46 4e 73  |r%,"Write: "+FNs|
00002e00  74 72 69 6e 67 30 28 72  30 2b 34 29 0d 0d 0c 05  |tring0(r0+4)....|
00002e10  e1 0d 0d 16 05 3a 0d 0d  20 3b f4 20 46 4e 73 6f  |.....:.. ;. FNso|
00002e20  63 6b 65 74 5f 67 65 74  70 65 65 72 6e 61 6d 65  |cket_getpeername|
00002e30  20 3a 20 52 65 61 64 20  74 68 65 20 6e 61 6d 65  | : Read the name|
00002e40  20 6f 66 20 74 68 65 20  6f 74 68 65 72 20 65 6e  | of the other en|
00002e50  64 0d 0d 2a 1f dd a4 73  6f 63 6b 65 74 5f 67 65  |d..*...socket_ge|
00002e60  74 70 65 65 72 6e 61 6d  65 28 73 6f 63 6b 25 29  |tpeername(sock%)|
00002e70  0d 0d 34 0b ea 20 72 30  2c 72 31 0d 0d 3e 26 f2  |..4.. r0,r1..>&.|
00002e80  73 6f 63 6b 65 74 5f 63  68 65 63 6b 28 73 6f 63  |socket_check(soc|
00002e90  6b 25 2c 22 47 65 74 50  65 65 72 4e 61 6d 65 22  |k%,"GetPeerName"|
00002ea0  29 0d 0d 48 11 21 73 6f  63 6b 74 65 6d 70 25 3d  |)..H.!socktemp%=|
00002eb0  31 36 0d 0d 52 3e c8 99  20 22 53 6f 63 6b 65 74  |16..R>.. "Socket|
00002ec0  5f 47 65 74 70 65 65 72  6e 61 6d 65 22 2c 73 6f  |_Getpeername",so|
00002ed0  63 6b 25 28 73 6f 63 6b  25 29 21 30 2c 73 6f 63  |ck%(sock%)!0,soc|
00002ee0  6b 61 64 64 72 25 2c 73  6f 63 6b 74 65 6d 70 25  |kaddr%,socktemp%|
00002ef0  0d 0d 5c 1f f4 20 22 58  49 6e 74 65 72 6e 65 74  |..\.. "XInternet|
00002f00  5f 47 65 74 48 6f 73 74  42 79 41 64 64 72 22 0d  |_GetHostByAddr".|
00002f10  0d 66 32 c8 99 20 26 36  36 30 30 31 2c 30 2c 73  |.f2.. &66001,0,s|
00002f20  6f 63 6b 61 64 64 72 25  2b 34 2c 34 2c 41 46 5f  |ockaddr%+4,4,AF_|
00002f30  49 4e 45 54 20 b8 20 2c  72 31 3b 66 6c 61 67 73  |INET . ,r1;flags|
00002f40  25 0d 0d 70 2b e7 20 28  66 6c 61 67 73 25 20 80  |%..p+. (flags% .|
00002f50  31 29 3d 30 20 80 20 72  31 3c 3e 30 20 8c 3d a4  |1)=0 . r1<>0 .=.|
00002f60  73 74 72 69 6e 67 30 28  21 72 31 29 0d 0d 7a 4c  |string0(!r1)..zL|
00002f70  3d c3 28 73 6f 63 6b 61  64 64 72 25 3f 34 29 2b  |=.(sockaddr%?4)+|
00002f80  22 2e 22 2b c3 28 73 6f  63 6b 61 64 64 72 25 3f  |"."+.(sockaddr%?|
00002f90  35 29 2b 22 2e 22 2b c3  28 73 6f 63 6b 61 64 64  |5)+"."+.(sockadd|
00002fa0  72 25 3f 36 29 2b 22 2e  22 2b c3 28 73 6f 63 6b  |r%?6)+"."+.(sock|
00002fb0  61 64 64 72 25 3f 37 29  0d 0d 84 05 3a 0d 0d 8e  |addr%?7)....:...|
00002fc0  41 f4 20 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |A. *************|
00002fd0  2a 2a 2a 20 48 6f 73 74  20 61 6e 64 20 73 65 72  |*** Host and ser|
00002fe0  76 69 63 65 20 73 70 65  63 69 66 69 63 20 2a 2a  |vice specific **|
00002ff0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 0d 0d  |**************..|
00003000  98 05 3a 0d 0d a2 3c f4  20 46 4e 69 6e 65 74 5f  |..:...<. FNinet_|
00003010  67 65 74 73 65 72 76 62  79 6e 61 6d 65 20 3a 20  |getservbyname : |
00003020  52 65 61 64 20 74 68 65  20 70 6f 72 74 20 66 72  |Read the port fr|
00003030  6f 6d 20 73 65 72 76 69  63 65 20 6e 61 6d 65 0d  |om service name.|
00003040  0d ac 26 dd a4 69 6e 65  74 5f 67 65 74 73 65 72  |..&..inet_getser|
00003050  76 62 79 6e 61 6d 65 28  6e 61 6d 65 24 2c 70 72  |vbyname(name$,pr|
00003060  6f 74 6f 24 29 0d 0d b6  14 ea 20 73 65 72 76 65  |oto$)..... serve|
00003070  6e 74 25 2c 70 6f 72 74  25 0d 0d c0 1c e7 20 bb  |nt%,port%..... .|
00003080  28 6e 61 6d 65 24 29 3c  3e 30 20 8c 3d bb 28 6e  |(name$)<>0 .=.(n|
00003090  61 6d 65 24 29 0d 0d ca  3b c8 99 20 22 49 6e 74  |ame$)...;.. "Int|
000030a0  65 72 6e 65 74 5f 47 65  74 53 65 72 76 69 63 65  |ernet_GetService|
000030b0  42 79 4e 61 6d 65 22 2c  6e 61 6d 65 24 2c 70 72  |ByName",name$,pr|
000030c0  6f 74 6f 24 20 b8 20 2c  73 65 72 76 65 6e 74 25  |oto$ . ,servent%|
000030d0  0d 0d d4 2b e7 20 73 65  72 76 65 6e 74 25 3d 30  |...+. servent%=0|
000030e0  20 8c 70 6f 72 74 25 3d  30 20 8b 70 6f 72 74 25  | .port%=0 .port%|
000030f0  3d 73 65 72 76 65 6e 74  25 21 38 0d 0d de 0a 3d  |=servent%!8....=|
00003100  70 6f 72 74 25 0d 0d e8  05 3a 0d 0d f2 3c f4 20  |port%....:...<. |
00003110  46 4e 69 6e 65 74 5f 67  65 74 73 65 72 76 62 79  |FNinet_getservby|
00003120  70 6f 72 74 20 3a 20 52  65 61 64 20 74 68 65 20  |port : Read the |
00003130  73 65 72 76 69 63 65 20  6e 61 6d 65 20 66 72 6f  |service name fro|
00003140  6d 20 70 6f 72 74 0d 0d  fc 26 dd a4 69 6e 65 74  |m port...&..inet|
00003150  5f 67 65 74 73 65 72 76  62 79 70 6f 72 74 28 70  |_getservbyport(p|
00003160  6f 72 74 25 2c 70 72 6f  74 6f 24 29 0d 0e 06 23  |ort%,proto$)...#|
00003170  ea 20 73 65 72 76 65 6e  74 25 2c 73 24 3a 70 6f  |. servent%,s$:po|
00003180  72 74 25 3d 70 6f 72 74  25 80 26 46 46 46 46 0d  |rt%=port%.&FFFF.|
00003190  0e 10 3b c8 99 20 22 49  6e 74 65 72 6e 65 74 5f  |..;.. "Internet_|
000031a0  47 65 74 53 65 72 76 69  63 65 42 79 50 6f 72 74  |GetServiceByPort|
000031b0  22 2c 70 6f 72 74 25 2c  70 72 6f 74 6f 24 20 b8  |",port%,proto$ .|
000031c0  20 2c 73 65 72 76 65 6e  74 25 0d 0e 1a 33 e7 20  | ,servent%...3. |
000031d0  73 65 72 76 65 6e 74 25  3d 30 20 8c 73 24 3d c3  |servent%=0 .s$=.|
000031e0  70 6f 72 74 25 20 8b 73  24 3d a4 73 74 72 69 6e  |port% .s$=.strin|
000031f0  67 30 28 21 73 65 72 76  65 6e 74 25 29 0d 0e 24  |g0(!servent%)..$|
00003200  07 3d 73 24 0d 0e 2e 05  3a 0d 0e 38 39 f4 20 46  |.=s$....:..89. F|
00003210  4e 69 6e 65 74 5f 67 65  74 68 6f 73 74 62 79 6e  |Ninet_gethostbyn|
00003220  61 6d 65 20 3a 20 52 65  74 75 72 6e 20 61 64 64  |ame : Return add|
00003230  72 65 73 73 20 6f 66 20  6e 61 6d 65 64 20 68 6f  |ress of named ho|
00003240  73 74 0d 0e 42 1f dd a4  69 6e 65 74 5f 67 65 74  |st..B...inet_get|
00003250  68 6f 73 74 62 79 6e 61  6d 65 28 68 6f 73 74 24  |hostbyname(host$|
00003260  29 0d 0e 4c 11 ea 20 70  74 72 25 2c 66 6c 61 67  |)..L.. ptr%,flag|
00003270  73 25 0d 0e 56 1f f4 20  22 58 49 6e 74 65 72 6e  |s%..V.. "XIntern|
00003280  65 74 5f 47 65 74 48 6f  73 74 42 79 4e 61 6d 65  |et_GetHostByName|
00003290  22 0d 0e 60 23 c8 99 20  26 36 36 30 30 30 2c 30  |"..`#.. &66000,0|
000032a0  2c 68 6f 73 74 24 20 b8  2c 70 74 72 25 3b 66 6c  |,host$ .,ptr%;fl|
000032b0  61 67 73 25 0d 0e 6a 21  e7 20 70 74 72 25 3d 30  |ags%..j!. ptr%=0|
000032c0  20 84 20 28 66 6c 61 67  73 25 20 80 20 31 29 3d  | . (flags% . 1)=|
000032d0  31 20 8c 3d 30 0d 0e 74  31 3d 21 21 28 70 74 72  |1 .=0..t1=!!(ptr|
000032e0  25 21 31 36 29 3a f4 20  59 65 73 2c 20 74 68 61  |%!16):. Yes, tha|
000032f0  74 20 69 73 20 72 69 67  68 74 2c 20 68 6f 6e 65  |t is right, hone|
00003300  73 74 20 3b 2d 29 0d 0e  7e 05 3a 0d 0e 88 43 f4  |st ;-)..~.:...C.|
00003310  20 46 4e 69 6e 65 74 5f  67 65 74 68 6f 73 74 62  | FNinet_gethostb|
00003320  79 61 64 64 72 20 3a 20  52 65 74 75 72 6e 20 6e  |yaddr : Return n|
00003330  61 6d 65 20 6f 66 20 68  6f 73 74 20 77 69 74 68  |ame of host with|
00003340  20 67 69 76 65 6e 20 61  64 64 72 65 73 73 0d 0e  | given address..|
00003350  92 1f dd a4 69 6e 65 74  5f 67 65 74 68 6f 73 74  |....inet_gethost|
00003360  62 79 61 64 64 72 28 61  64 64 72 25 29 0d 0e 9c  |byaddr(addr%)...|
00003370  22 ea 20 70 74 72 25 2c  66 6c 61 67 73 25 3a 21  |". ptr%,flags%:!|
00003380  73 6f 63 6b 74 65 6d 70  25 3d 61 64 64 72 25 0d  |socktemp%=addr%.|
00003390  0e a6 1f f4 20 22 58 49  6e 74 65 72 6e 65 74 5f  |.... "XInternet_|
000033a0  47 65 74 48 6f 73 74 42  79 41 64 64 72 22 0d 0e  |GetHostByAddr"..|
000033b0  b0 32 c8 99 20 26 36 36  30 30 31 2c 30 2c 73 6f  |.2.. &66001,0,so|
000033c0  63 6b 74 65 6d 70 25 2c  34 2c 41 46 5f 49 4e 45  |cktemp%,4,AF_INE|
000033d0  54 20 b8 72 2c 70 74 72  25 3b 66 6c 61 67 73 25  |T .r,ptr%;flags%|
000033e0  0d 0e ba 2f f4 20 49 46  20 28 66 6c 61 67 73 25  |.../. IF (flags%|
000033f0  20 41 4e 44 20 31 29 20  54 48 45 4e 50 52 49 4e  | AND 1) THENPRIN|
00003400  54 46 4e 73 74 72 69 6e  67 30 28 72 2b 34 29 0d  |TFNstring0(r+4).|
00003410  0e c4 67 e7 20 70 74 72  25 3d 30 20 84 20 28 66  |..g. ptr%=0 . (f|
00003420  6c 61 67 73 25 20 80 20  31 29 3d 31 20 8c 3d c3  |lags% . 1)=1 .=.|
00003430  28 73 6f 63 6b 74 65 6d  70 25 3f 30 29 2b 22 2e  |(socktemp%?0)+".|
00003440  22 2b c3 28 73 6f 63 6b  74 65 6d 70 25 3f 31 29  |"+.(socktemp%?1)|
00003450  2b 22 2e 22 2b c3 28 73  6f 63 6b 74 65 6d 70 25  |+"."+.(socktemp%|
00003460  3f 32 29 2b 22 2e 22 2b  c3 28 73 6f 63 6b 74 65  |?2)+"."+.(sockte|
00003470  6d 70 25 3f 33 29 0d 0e  ce 14 3d a4 73 74 72 69  |mp%?3)....=.stri|
00003480  6e 67 30 28 21 70 74 72  25 29 0d 0e d8 05 3a 0d  |ng0(!ptr%)....:.|
00003490  0e e2 37 f4 20 46 4e 69  6e 65 74 5f 63 72 65 61  |..7. FNinet_crea|
000034a0  74 65 73 65 72 76 6d 65  6e 75 20 3a 20 43 72 65  |teservmenu : Cre|
000034b0  61 74 65 20 61 20 6d 65  6e 75 20 6f 66 20 73 65  |ate a menu of se|
000034c0  72 76 69 63 65 73 0d 0e  ec 27 dd a4 69 6e 65 74  |rvices...'..inet|
000034d0  5f 63 72 65 61 74 65 73  65 72 76 6d 65 6e 75 28  |_createservmenu(|
000034e0  6e 61 6d 65 24 2c 70 72  6f 74 6f 24 29 0d 0e f6  |name$,proto$)...|
000034f0  0b ea 20 6d 65 6e 75 25  0d 0f 00 11 e7 20 70 72  |.. menu%..... pr|
00003500  6f 74 6f 24 3d 22 22 20  8c 0d 0f 0a 32 20 c8 99  |oto$="" ....2 ..|
00003510  20 22 49 6e 74 65 72 6e  65 74 5f 47 65 74 53 65  | "Internet_GetSe|
00003520  72 76 69 63 65 73 4d 65  6e 75 22 2c 6e 61 6d 65  |rvicesMenu",name|
00003530  24 2c 30 20 b8 20 6d 65  6e 75 25 0d 0f 14 05 cc  |$,0 . menu%.....|
00003540  0d 0f 1e 37 20 c8 99 20  22 49 6e 74 65 72 6e 65  |...7 .. "Interne|
00003550  74 5f 47 65 74 53 65 72  76 69 63 65 73 4d 65 6e  |t_GetServicesMen|
00003560  75 22 2c 6e 61 6d 65 24  2c 70 72 6f 74 6f 24 20  |u",name$,proto$ |
00003570  b8 20 6d 65 6e 75 25 0d  0f 28 05 cd 0d 0f 32 0a  |. menu%..(....2.|
00003580  3d 6d 65 6e 75 25 0d 0f  3c 05 3a 0d 0f 46 39 f4  |=menu%..<.:..F9.|
00003590  20 46 4e 69 6e 65 74 5f  64 65 63 6f 64 65 65 72  | FNinet_decodeer|
000035a0  72 6f 72 20 3a 20 44 65  63 6f 64 65 73 20 61 6e  |ror : Decodes an|
000035b0  20 65 72 72 6f 72 20 69  6e 74 6f 20 61 20 73 74  | error into a st|
000035c0  72 69 6e 67 0d 0f 50 1c  dd a4 69 6e 65 74 5f 64  |ring..P...inet_d|
000035d0  65 63 6f 64 65 65 72 72  6f 72 28 65 72 72 25 29  |ecodeerror(err%)|
000035e0  0d 0f 5a 2b ea 20 61 24  3a c8 99 20 22 49 6e 74  |..Z+. a$:.. "Int|
000035f0  65 72 6e 65 74 5f 44 65  63 6f 64 65 45 72 72 6f  |ernet_DecodeErro|
00003600  72 22 2c 65 72 72 25 20  b8 61 24 0d 0f 64 07 3d  |r",err% .a$..d.=|
00003610  61 24 0d 0f 6e 05 3a 0d  0f 78 44 f4 20 2a 2a 2a  |a$..n.:..xD. ***|
00003620  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 20 4d  |************** M|
00003630  75 6c 74 69 2d 74 61 73  6b 69 6e 67 20 52 65 73  |ulti-tasking Res|
00003640  6f 6c 76 65 72 20 73 74  75 66 66 20 2a 2a 2a 2a  |olver stuff ****|
00003650  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 0d 0f 82 05 3a  |***********....:|
00003660  0d 0f 8c 42 f4 20 46 4e  69 6e 65 74 5f 6d 74 72  |...B. FNinet_mtr|
00003670  65 73 6f 6c 76 65 72 20  3a 20 49 73 20 74 68 65  |esolver : Is the|
00003680  72 65 20 4d 75 6c 74 69  74 61 73 6b 69 6e 67 20  |re Multitasking |
00003690  72 65 73 6f 6c 76 65 72  20 70 72 65 73 65 6e 74  |resolver present|
000036a0  20 3f 0d 0f 96 15 dd a4  69 6e 65 74 5f 6d 74 72  | ?......inet_mtr|
000036b0  65 73 6f 6c 76 65 72 0d  0f a0 11 ea 20 66 6c 61  |esolver..... fla|
000036c0  67 73 25 2c 70 74 72 25  0d 0f aa 34 c8 99 20 22  |gs%,ptr%...4.. "|
000036d0  4f 53 5f 4d 6f 64 75 6c  65 22 2c 31 38 2c 22 44  |OS_Module",18,"D|
000036e0  4e 53 52 65 73 6f 6c 76  65 72 22 20 b8 20 2c 2c  |NSResolver" . ,,|
000036f0  2c 70 74 72 25 3b 66 6c  61 67 73 25 0d 0f b4 16  |,ptr%;flags%....|
00003700  e7 20 28 66 6c 61 67 73  25 20 80 20 31 29 3d 30  |. (flags% . 1)=0|
00003710  20 8c 0d 0f be 2a 20 e7  20 bb 28 a4 73 74 72 69  | ....* . .(.stri|
00003720  6e 67 30 28 28 70 74 72  25 21 31 30 29 2b 31 33  |ng0((ptr%!10)+13|
00003730  29 29 3e 3d 31 2e 30 33  20 8c 3d b9 0d 0f c8 05  |))>=1.03 .=.....|
00003740  cd 0d 0f d2 06 3d a3 0d  0f dc 05 3a 0d 0f e6 44  |.....=.....:...D|
00003750  f4 20 46 4e 69 6e 65 74  5f 73 74 61 72 74 6d 74  |. FNinet_startmt|
00003760  67 65 74 68 6f 73 74 62  79 6e 61 6d 65 20 3a 20  |gethostbyname : |
00003770  53 74 61 72 74 20 61 20  6d 75 6c 74 69 74 61 73  |Start a multitas|
00003780  6b 69 6e 67 20 6e 61 6d  65 20 6c 6f 6f 6b 75 70  |king name lookup|
00003790  0d 0f f0 32 f4 20 52 65  74 75 72 6e 73 20 68 61  |...2. Returns ha|
000037a0  6e 64 6c 65 20 69 66 20  74 68 69 73 20 73 75 63  |ndle if this suc|
000037b0  63 65 65 64 65 64 20 69  6e 20 73 74 61 72 74 69  |ceeded in starti|
000037c0  6e 67 0d 0f fa 26 dd a4  69 6e 65 74 5f 73 74 61  |ng...&..inet_sta|
000037d0  72 74 6d 74 67 65 74 68  6f 73 74 62 79 6e 61 6d  |rtmtgethostbynam|
000037e0  65 28 68 6f 73 74 24 29  0d 10 04 11 ea 20 70 74  |e(host$)..... pt|
000037f0  72 25 2c 66 6c 61 67 73  25 0d 10 0e 38 c8 99 20  |r%,flags%...8.. |
00003800  22 58 44 4e 53 52 65 73  6f 6c 76 65 72 5f 4d 54  |"XDNSResolver_MT|
00003810  47 65 74 48 6f 73 74 42  79 4e 61 6d 65 22 2c 68  |GetHostByName",h|
00003820  6f 73 74 24 20 b8 70 74  72 25 3b 66 6c 61 67 73  |ost$ .ptr%;flags|
00003830  25 0d 10 18 18 e7 20 28  66 6c 61 67 73 25 20 80  |%..... (flags% .|
00003840  20 31 29 3d 31 20 8c 3d  a3 0d 10 22 1c f4 20 48  | 1)=1 .=...".. H|
00003850  6f 6f 6b 20 75 73 20 69  6e 74 6f 20 74 68 65 20  |ook us into the |
00003860  63 68 61 69 6e 0d 10 2c  43 66 6c 61 67 73 25 3d  |chain..,Cflags%=|
00003870  a4 63 6c 61 69 6d 28 38  29 3a 21 66 6c 61 67 73  |.claim(8):!flags|
00003880  25 3d 6d 74 63 68 61 69  6e 25 3a 66 6c 61 67 73  |%=mtchain%:flags|
00003890  25 21 34 3d 70 74 72 25  3a 6d 74 63 68 61 69 6e  |%!4=ptr%:mtchain|
000038a0  25 3d 66 6c 61 67 73 25  0d 10 36 09 3d 70 74 72  |%=flags%..6.=ptr|
000038b0  25 0d 10 40 05 3a 0d 10  4a 42 f4 20 46 4e 69 6e  |%..@.:..JB. FNin|
000038c0  65 74 5f 73 74 61 72 74  6d 74 67 65 74 68 6f 73  |et_startmtgethos|
000038d0  74 62 79 61 64 64 72 20  3a 20 53 74 61 72 74 20  |tbyaddr : Start |
000038e0  6d 75 6c 74 69 74 61 73  6b 69 6e 67 20 61 64 64  |multitasking add|
000038f0  72 20 6c 6f 6f 6b 75 70  0d 10 54 32 f4 20 52 65  |r lookup..T2. Re|
00003900  74 75 72 6e 73 20 68 61  6e 64 6c 65 20 69 66 20  |turns handle if |
00003910  74 68 69 73 20 73 75 63  63 65 65 64 65 64 20 69  |this succeeded i|
00003920  6e 20 73 74 61 72 74 69  6e 67 0d 10 5e 26 dd a4  |n starting..^&..|
00003930  69 6e 65 74 5f 73 74 61  72 74 6d 74 67 65 74 68  |inet_startmtgeth|
00003940  6f 73 74 62 79 61 64 64  72 28 61 64 64 72 25 29  |ostbyaddr(addr%)|
00003950  0d 10 68 22 ea 20 70 74  72 25 2c 66 6c 61 67 73  |..h". ptr%,flags|
00003960  25 3a 21 73 6f 63 6b 74  65 6d 70 25 3d 61 64 64  |%:!socktemp%=add|
00003970  72 25 0d 10 72 46 c8 99  20 22 58 44 4e 53 52 65  |r%..rF.. "XDNSRe|
00003980  73 6f 6c 76 65 72 5f 4d  54 47 65 74 48 6f 73 74  |solver_MTGetHost|
00003990  42 79 41 64 64 72 22 2c  73 6f 63 6b 74 65 6d 70  |ByAddr",socktemp|
000039a0  25 2c 34 2c 41 46 5f 49  4e 45 54 20 b8 70 74 72  |%,4,AF_INET .ptr|
000039b0  25 3b 66 6c 61 67 73 25  0d 10 7c 18 e7 20 28 66  |%;flags%..|.. (f|
000039c0  6c 61 67 73 25 20 80 20  31 29 3d 31 20 8c 3d a3  |lags% . 1)=1 .=.|
000039d0  0d 10 86 1c f4 20 48 6f  6f 6b 20 75 73 20 69 6e  |..... Hook us in|
000039e0  74 6f 20 74 68 65 20 63  68 61 69 6e 0d 10 90 43  |to the chain...C|
000039f0  66 6c 61 67 73 25 3d a4  63 6c 61 69 6d 28 38 29  |flags%=.claim(8)|
00003a00  3a 21 66 6c 61 67 73 25  3d 6d 74 63 68 61 69 6e  |:!flags%=mtchain|
00003a10  25 3a 66 6c 61 67 73 25  21 34 3d 70 74 72 25 3a  |%:flags%!4=ptr%:|
00003a20  6d 74 63 68 61 69 6e 25  3d 66 6c 61 67 73 25 0d  |mtchain%=flags%.|
00003a30  10 9a 09 3d 70 74 72 25  0d 10 a4 05 3a 0d 10 ae  |...=ptr%....:...|
00003a40  41 f4 20 46 4e 69 6e 65  74 5f 63 68 65 63 6b 6d  |A. FNinet_checkm|
00003a50  74 71 75 65 72 79 20 3a  20 43 68 65 63 6b 20 70  |tquery : Check p|
00003a60  72 6f 67 72 65 73 73 20  6f 66 20 6d 75 6c 74 69  |rogress of multi|
00003a70  74 61 73 6b 69 6e 67 20  6c 6f 6f 6b 75 70 0d 10  |tasking lookup..|
00003a80  b8 3c f4 20 52 65 74 75  72 6e 73 20 46 41 4c 53  |.<. Returns FALS|
00003a90  45 20 69 66 20 71 75 65  72 79 20 66 61 69 6c 65  |E if query faile|
00003aa0  64 20 28 73 74 61 63 6b  20 66 61 69 6c 75 72 65  |d (stack failure|
00003ab0  29 2c 20 54 52 55 45 20  69 66 0d 10 c2 33 f4 20  |), TRUE if...3. |
00003ac0  71 75 65 72 79 20 63 6f  6d 70 6c 65 74 65 64 20  |query completed |
00003ad0  6f 6b 2c 20 61 6e 64 20  31 20 69 66 20 69 74 27  |ok, and 1 if it'|
00003ae0  73 20 73 74 69 6c 6c 20  67 6f 69 6e 67 0d 10 cc  |s still going...|
00003af0  1f dd a4 69 6e 65 74 5f  63 68 65 63 6b 6d 74 71  |...inet_checkmtq|
00003b00  75 65 72 79 28 71 75 65  72 79 25 29 0d 10 d6 11  |uery(query%)....|
00003b10  ea 20 72 65 73 25 2c 66  6c 61 67 73 25 0d 10 e0  |. res%,flags%...|
00003b20  30 c8 99 20 22 58 44 4e  53 52 65 73 6f 6c 76 65  |0.. "XDNSResolve|
00003b30  72 5f 43 68 65 63 6b 22  2c 71 75 65 72 79 25 20  |r_Check",query% |
00003b40  b8 20 72 65 73 25 3b 66  6c 61 67 73 25 0d 10 ea  |. res%;flags%...|
00003b50  2f e7 20 28 66 6c 61 67  73 25 20 80 20 31 29 3d  |/. (flags% . 1)=|
00003b60  31 20 84 20 72 65 73 25  3d 34 20 8c 3d a3 20 8b  |1 . res%=4 .=. .|
00003b70  e7 20 72 65 73 25 3d 33  20 8c 3d b9 0d 10 f4 06  |. res%=3 .=.....|
00003b80  3d 31 0d 10 fe 05 3a 0d  11 08 3f f4 20 50 52 4f  |=1....:...?. PRO|
00003b90  43 69 6e 65 74 5f 6b 69  6c 6c 6d 74 71 75 65 72  |Cinet_killmtquer|
00003ba0  79 20 3a 20 46 6f 72 67  65 74 20 61 62 6f 75 74  |y : Forget about|
00003bb0  20 61 20 6d 75 6c 74 69  74 61 73 6b 69 6e 67 20  | a multitasking |
00003bc0  6c 6f 6f 6b 75 70 0d 11  12 1e dd f2 69 6e 65 74  |lookup......inet|
00003bd0  5f 6b 69 6c 6c 6d 74 71  75 65 72 79 28 71 75 65  |_killmtquery(que|
00003be0  72 79 25 29 0d 11 1c 0e  ea 20 6c 25 2c 70 25 2c  |ry%)..... l%,p%,|
00003bf0  6e 25 0d 11 26 24 c8 99  20 22 58 44 4e 53 52 65  |n%..&$.. "XDNSRe|
00003c00  73 6f 6c 76 65 72 5f 44  69 73 70 6f 73 65 22 2c  |solver_Dispose",|
00003c10  71 75 65 72 79 25 0d 11  30 0f 70 25 3d 6d 74 63  |query%..0.p%=mtc|
00003c20  68 61 69 6e 25 0d 11 3a  13 e7 20 70 25 21 34 3d  |hain%..:.. p%!4=|
00003c30  71 75 65 72 79 25 20 8c  0d 11 44 1e 20 6d 74 63  |query% ...D. mtc|
00003c40  68 61 69 6e 25 3d 21 70  25 3a f2 72 65 6c 65 61  |hain%=!p%:.relea|
00003c50  73 65 28 70 25 29 0d 11  4e 05 cc 0d 11 58 11 20  |se(p%)..N....X. |
00003c60  6c 25 3d 70 25 3a 70 25  3d 21 70 25 0d 11 62 0d  |l%=p%:p%=!p%..b.|
00003c70  20 c8 95 20 70 25 3c 3e  30 0d 11 6c 2f 20 20 6e  | .. p%<>0..l/  n|
00003c80  25 3d 21 70 25 3a e7 20  70 25 21 34 3d 71 75 65  |%=!p%:. p%!4=que|
00003c90  72 79 25 20 8c f2 72 65  6c 65 61 73 65 28 70 25  |ry% ..release(p%|
00003ca0  29 3a 21 6c 25 3d 6e 25  0d 11 76 0b 20 20 70 25  |):!l%=n%..v.  p%|
00003cb0  3d 6e 25 0d 11 80 06 20  ce 0d 11 8a 05 cd 0d 11  |=n%.... ........|
00003cc0  94 05 e1 0d 11 9e 05 3a  0d 11 a8 41 f4 20 46 4e  |.......:...A. FN|
00003cd0  69 6e 65 74 5f 6d 74 67  65 74 68 6f 73 74 62 79  |inet_mtgethostby|
00003ce0  6e 61 6d 65 20 3a 20 52  65 74 72 69 65 76 65 20  |name : Retrieve |
00003cf0  61 6e 20 61 64 64 72 65  73 73 20 66 72 6f 6d 20  |an address from |
00003d00  61 20 68 6f 73 74 65 6e  74 0d 11 b2 3a f4 20 52  |a hostent...:. R|
00003d10  65 74 75 72 6e 73 20 74  68 65 20 72 65 73 75 6c  |eturns the resul|
00003d20  74 20 6f 66 20 68 6f 73  74 20 6c 6f 6f 6b 75 70  |t of host lookup|
00003d30  2c 20 6f 72 20 30 20 69  66 20 69 74 20 66 61 69  |, or 0 if it fai|
00003d40  6c 65 64 0d 11 bc 22 dd  a4 69 6e 65 74 5f 6d 74  |led..."..inet_mt|
00003d50  67 65 74 68 6f 73 74 62  79 6e 61 6d 65 28 71 75  |gethostbyname(qu|
00003d60  65 72 79 25 29 0d 11 c6  17 ea 20 70 74 72 25 2c  |ery%)..... ptr%,|
00003d70  66 6c 61 67 73 25 2c 61  64 64 72 25 0d 11 d0 34  |flags%,addr%...4|
00003d80  c8 99 20 22 58 44 4e 53  52 65 73 6f 6c 76 65 72  |.. "XDNSResolver|
00003d90  5f 47 65 74 41 6e 73 77  65 72 22 2c 71 75 65 72  |_GetAnswer",quer|
00003da0  79 25 20 b8 20 70 74 72  25 3b 66 6c 61 67 73 25  |y% . ptr%;flags%|
00003db0  0d 11 da 21 e7 20 70 74  72 25 3c 3e 30 20 8c 20  |...!. ptr%<>0 . |
00003dc0  61 64 64 72 25 3d 21 21  28 70 74 72 25 21 31 36  |addr%=!!(ptr%!16|
00003dd0  29 0d 11 e4 1d f2 69 6e  65 74 5f 6b 69 6c 6c 6d  |).....inet_killm|
00003de0  74 71 75 65 72 79 28 71  75 65 72 79 25 29 0d 11  |tquery(query%)..|
00003df0  ee 21 e7 20 70 74 72 25  3d 30 20 84 20 28 66 6c  |.!. ptr%=0 . (fl|
00003e00  61 67 73 25 20 80 20 31  29 3d 31 20 8c 3d 30 0d  |ags% . 1)=1 .=0.|
00003e10  11 f8 0a 3d 61 64 64 72  25 0d 12 02 05 3a 0d 12  |...=addr%....:..|
00003e20  0c 3d f4 20 46 4e 69 6e  65 74 5f 6d 74 67 65 74  |.=. FNinet_mtget|
00003e30  68 6f 73 74 62 79 61 64  64 72 20 3a 20 52 65 74  |hostbyaddr : Ret|
00003e40  72 69 65 76 65 20 61 20  6e 61 6d 65 20 66 72 6f  |rieve a name fro|
00003e50  6d 20 61 20 68 6f 73 74  65 6e 74 0d 12 16 41 f4  |m a hostent...A.|
00003e60  20 52 65 74 75 72 6e 73  20 74 68 65 20 72 65 73  | Returns the res|
00003e70  75 6c 74 20 6f 66 20 61  6e 20 61 64 64 72 65 73  |ult of an addres|
00003e80  73 20 6c 6f 6f 6b 75 70  2c 20 6f 72 20 22 22 20  |s lookup, or "" |
00003e90  69 66 20 69 74 20 66 61  69 6c 65 64 0d 12 20 22  |if it failed.. "|
00003ea0  dd a4 69 6e 65 74 5f 6d  74 67 65 74 68 6f 73 74  |..inet_mtgethost|
00003eb0  62 79 61 64 64 72 28 71  75 65 72 79 25 29 0d 12  |byaddr(query%)..|
00003ec0  2a 17 ea 20 70 74 72 25  2c 66 6c 61 67 73 25 2c  |*.. ptr%,flags%,|
00003ed0  68 6f 73 74 24 0d 12 34  34 c8 99 20 22 58 44 4e  |host$..44.. "XDN|
00003ee0  53 52 65 73 6f 6c 76 65  72 5f 47 65 74 41 6e 73  |SResolver_GetAns|
00003ef0  77 65 72 22 2c 71 75 65  72 79 25 20 b8 20 70 74  |wer",query% . pt|
00003f00  72 25 3b 66 6c 61 67 73  25 0d 12 3e 24 e7 20 70  |r%;flags%..>$. p|
00003f10  74 72 25 3c 3e 30 20 8c  68 6f 73 74 24 3d a4 73  |tr%<>0 .host$=.s|
00003f20  74 72 69 6e 67 30 28 21  70 74 72 25 29 0d 12 48  |tring0(!ptr%)..H|
00003f30  1d f2 69 6e 65 74 5f 6b  69 6c 6c 6d 74 71 75 65  |..inet_killmtque|
00003f40  72 79 28 71 75 65 72 79  25 29 0d 12 52 22 e7 20  |ry(query%)..R". |
00003f50  70 74 72 25 3d 30 20 84  20 28 66 6c 61 67 73 25  |ptr%=0 . (flags%|
00003f60  20 80 20 31 29 3d 31 20  8c 3d 22 22 0d 12 5c 0a  | . 1)=1 .=""..\.|
00003f70  3d 68 6f 73 74 24 0d 12  66 05 3a 0d 12 70 41 f4  |=host$..f.:..pA.|
00003f80  20 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  | ***************|
00003f90  2a 2a 2a 2a 2a 20 42 75  66 66 65 72 20 72 6f 75  |***** Buffer rou|
00003fa0  74 69 6e 65 73 20 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |tines **********|
00003fb0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 0d 12 7a 05  |************..z.|
00003fc0  3a 0d 12 84 3a f4 20 46  4e 62 75 66 66 65 72 5f  |:...:. FNbuffer_|
00003fd0  67 65 74 77 6f 72 64 20  3a 20 52 65 61 64 20 74  |getword : Read t|
00003fe0  68 65 20 66 69 72 73 74  20 77 6f 72 64 20 66 72  |he first word fr|
00003ff0  6f 6d 20 61 20 62 75 66  66 65 72 0d 12 8e 28 dd  |om a buffer...(.|
00004000  a4 62 75 66 66 65 72 5f  67 65 74 77 6f 72 64 28  |.buffer_getword(|
00004010  73 74 61 72 74 25 2c 6c  65 6e 25 2c f8 20 70 74  |start%,len%,. pt|
00004020  72 25 29 0d 12 98 0e ea  20 61 24 3a 61 24 3d 22  |r%)..... a$:a$="|
00004030  22 0d 12 a2 2b c8 95 20  73 74 61 72 74 25 3f 70  |"...+.. start%?p|
00004040  74 72 25 3d 33 32 20 80  20 70 74 72 25 3c 6c 65  |tr%=32 . ptr%<le|
00004050  6e 25 3a 70 74 72 25 2b  3d 31 3a ce 0d 12 ac 15  |n%:ptr%+=1:.....|
00004060  e7 20 70 74 72 25 3e 3d  6c 65 6e 25 20 8c 3d 22  |. ptr%>=len% .="|
00004070  22 0d 12 b6 05 f5 0d 12  c0 1f 20 61 24 2b 3d bd  |"......... a$+=.|
00004080  28 73 74 61 72 74 25 3f  70 74 72 25 29 3a 70 74  |(start%?ptr%):pt|
00004090  72 25 2b 3d 31 0d 12 ca  4e fd 20 73 74 61 72 74  |r%+=1...N. start|
000040a0  25 3f 70 74 72 25 3d 33  32 20 84 73 74 61 72 74  |%?ptr%=32 .start|
000040b0  25 3f 70 74 72 25 3d 31  30 20 84 73 74 61 72 74  |%?ptr%=10 .start|
000040c0  25 3f 70 74 72 25 3d 31  33 20 84 73 74 61 72 74  |%?ptr%=13 .start|
000040d0  25 3f 70 74 72 25 3d 30  20 84 70 74 72 25 3d 6c  |%?ptr%=0 .ptr%=l|
000040e0  65 6e 25 0d 12 d4 2a e7  20 73 74 61 72 74 25 3f  |en%...*. start%?|
000040f0  70 74 72 25 3d 33 32 20  80 20 70 74 72 25 3c 3e  |ptr%=32 . ptr%<>|
00004100  6c 65 6e 25 20 8c 70 74  72 25 2b 3d 31 0d 12 de  |len% .ptr%+=1...|
00004110  07 3d 61 24 0d 12 e8 05  3a 0d 12 f2 40 f4 20 46  |.=a$....:...@. F|
00004120  4e 62 75 66 66 65 72 5f  67 65 74 72 65 73 74 20  |Nbuffer_getrest |
00004130  3a 20 52 65 61 64 20 74  68 65 20 72 65 73 74 20  |: Read the rest |
00004140  6f 66 20 74 68 65 20 62  75 66 66 65 72 20 74 6f  |of the buffer to|
00004150  20 61 20 73 74 72 69 6e  67 0d 12 fc 28 dd a4 62  | a string...(..b|
00004160  75 66 66 65 72 5f 67 65  74 72 65 73 74 28 73 74  |uffer_getrest(st|
00004170  61 72 74 25 2c 6c 65 6e  25 2c f8 20 70 74 72 25  |art%,len%,. ptr%|
00004180  29 0d 13 06 0e ea 20 61  24 3a 61 24 3d 22 22 0d  |)..... a$:a$="".|
00004190  13 10 52 c8 95 20 28 ac  20 28 73 74 61 72 74 25  |..R.. (. (start%|
000041a0  3f 70 74 72 25 3d 31 30  20 84 73 74 61 72 74 25  |?ptr%=10 .start%|
000041b0  3f 70 74 72 25 3d 31 33  20 84 20 73 74 61 72 74  |?ptr%=13 . start|
000041c0  25 3f 70 74 72 25 3d 30  20 84 70 74 72 25 3d 6c  |%?ptr%=0 .ptr%=l|
000041d0  65 6e 25 29 29 20 80 20  a9 28 61 24 29 3c 32 35  |en%)) . .(a$)<25|
000041e0  34 0d 13 1a 1f 20 61 24  2b 3d bd 28 73 74 61 72  |4.... a$+=.(star|
000041f0  74 25 3f 70 74 72 25 29  3a 70 74 72 25 2b 3d 31  |t%?ptr%):ptr%+=1|
00004200  0d 13 24 05 ce 0d 13 2e  4c e7 20 28 73 74 61 72  |..$.....L. (star|
00004210  74 25 3f 70 74 72 25 3d  31 30 20 84 73 74 61 72  |t%?ptr%=10 .star|
00004220  74 25 3f 70 74 72 25 3d  31 33 20 84 20 73 74 61  |t%?ptr%=13 . sta|
00004230  72 74 25 3f 70 74 72 25  3d 30 29 20 80 20 70 74  |rt%?ptr%=0) . pt|
00004240  72 25 3c 3e 6c 65 6e 25  20 8c 70 74 72 25 2b 3d  |r%<>len% .ptr%+=|
00004250  31 0d 13 38 07 3d 61 24  0d 13 42 05 3a 0d 13 4c  |1..8.=a$..B.:..L|
00004260  41 f4 20 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |A. *************|
00004270  2a 2a 2a 2a 2a 2a 2a 2a  20 4c 6f 67 67 69 6e 67  |******** Logging|
00004280  20 72 6f 75 74 69 6e 65  73 20 2a 2a 2a 2a 2a 2a  | routines ******|
00004290  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 0d 13  |**************..|
000042a0  56 05 3a 0d 13 60 2d f4  20 50 52 4f 43 73 79 73  |V.:..`-. PROCsys|
000042b0  6c 6f 67 20 3a 20 6c 6f  67 20 61 20 6c 69 6e 65  |log : log a line|
000042c0  20 74 6f 20 74 68 65 20  6c 6f 67 20 66 69 6c 65  | to the log file|
000042d0  0d 13 6a 13 dd f2 73 79  73 6c 6f 67 28 6c 25 2c  |..j...syslog(l%,|
000042e0  6d 24 29 0d 13 74 18 f4  20 58 53 79 73 4c 6f 67  |m$)..t.. XSysLog|
000042f0  5f 4c 6f 67 4d 65 73 73  61 67 65 0d 13 7e 1c c8  |_LogMessage..~..|
00004300  99 20 26 36 43 38 38 30  2c 41 70 70 6e 61 6d 65  |. &6C880,Appname|
00004310  24 2c 6d 24 2c 6c 25 0d  13 88 05 e1 0d 13 92 05  |$,m$,l%.........|
00004320  3a 0d 13 9c 2d f4 20 46  4e 6c 6f 67 5f 6f 70 65  |:...-. FNlog_ope|
00004330  6e 73 65 73 73 69 6f 6e  20 3a 20 53 74 61 72 74  |nsession : Start|
00004340  20 61 20 73 65 73 73 69  6f 6e 20 6c 6f 67 0d 13  | a session log..|
00004350  a6 19 dd a4 6c 6f 67 5f  6f 70 65 6e 73 65 73 73  |....log_opensess|
00004360  69 6f 6e 28 6c 25 29 0d  13 b0 1c f4 20 58 53 79  |ion(l%)..... XSy|
00004370  73 4c 6f 67 5f 4f 70 65  6e 53 65 73 73 69 6f 6e  |sLog_OpenSession|
00004380  4c 6f 67 0d 13 ba 1e c8  99 20 26 36 43 38 38 38  |Log...... &6C888|
00004390  2c 41 70 70 6e 61 6d 65  24 2c 6c 25 20 b8 20 6c  |,Appname$,l% . l|
000043a0  25 0d 13 c4 07 3d 6c 25  0d 13 ce 05 3a 0d 13 d8  |%....=l%....:...|
000043b0  1a f4 20 50 52 4f 43 6c  6f 67 5f 63 6c 6f 73 65  |.. PROClog_close|
000043c0  73 65 73 73 69 6f 6e 0d  13 e2 1a dd f2 6c 6f 67  |session......log|
000043d0  5f 63 6c 6f 73 65 73 65  73 73 69 6f 6e 28 6c 25  |_closesession(l%|
000043e0  29 0d 13 ec 1d f4 20 58  53 79 73 4c 6f 67 5f 43  |)..... XSysLog_C|
000043f0  6c 6f 73 65 53 65 73 73  69 6f 6e 4c 6f 67 0d 13  |loseSessionLog..|
00004400  f6 10 c8 99 20 26 36 43  38 38 39 2c 6c 25 0d 14  |.... &6C889,l%..|
00004410  00 05 e1 0d 14 0a 05 3a  0d 14 14 31 f4 20 46 4e  |.......:...1. FN|
00004420  6c 6f 67 5f 73 65 73 73  69 6f 6e 20 3a 20 4c 6f  |log_session : Lo|
00004430  67 20 61 20 6c 69 6e 65  20 74 6f 20 61 20 73 65  |g a line to a se|
00004440  73 73 69 6f 6e 20 6c 6f  67 0d 14 1e 1d dd f2 6c  |ssion log......l|
00004450  6f 67 5f 73 65 73 73 69  6f 6e 28 6c 6f 67 25 2c  |og_session(log%,|
00004460  6c 25 2c 6d 24 29 0d 14  28 18 f4 20 58 53 79 73  |l%,m$)..(.. XSys|
00004470  4c 6f 67 5f 4c 6f 67 4d  65 73 73 61 67 65 0d 14  |Log_LogMessage..|
00004480  32 18 c8 99 20 26 36 43  38 38 30 2c 6c 6f 67 25  |2... &6C880,log%|
00004490  2c 6d 24 2c 6c 25 0d 14  3c 05 e1 0d 14 46 05 3a  |,m$,l%..<....F.:|
000044a0  0d 14 50 2a f4 20 50 52  4f 43 6c 6f 67 5f 69 6e  |..P*. PROClog_in|
000044b0  64 65 6e 74 20 3a 20 69  6e 64 65 6e 74 20 74 68  |dent : indent th|
000044c0  65 20 6c 6f 67 20 66 69  6c 65 0d 14 5a 14 dd f2  |e log file..Z...|
000044d0  6c 6f 67 5f 69 6e 64 65  6e 74 28 6c 25 29 0d 14  |log_indent(l%)..|
000044e0  64 14 f4 20 58 53 79 73  4c 6f 67 5f 49 6e 64 65  |d.. XSysLog_Inde|
000044f0  6e 74 0d 14 6e 2e e7 20  6c 25 3c 3e 2d 31 20 8c  |nt..n.. l%<>-1 .|
00004500  c8 99 20 26 36 43 38 38  35 2c 6c 25 20 8b c8 99  |.. &6C885,l% ...|
00004510  20 26 36 43 38 38 35 2c  41 70 70 6e 61 6d 65 24  | &6C885,Appname$|
00004520  0d 14 78 05 e1 0d 14 82  05 3a 0d 14 8c 37 f4 20  |..x......:...7. |
00004530  50 52 4f 43 6c 6f 67 5f  6f 75 74 64 65 6e 74 20  |PROClog_outdent |
00004540  3a 20 72 65 6d 6f 76 65  20 69 6e 64 65 6e 74 20  |: remove indent |
00004550  66 72 6f 6d 20 74 68 65  20 6c 6f 67 20 66 69 6c  |from the log fil|
00004560  65 0d 14 96 15 dd f2 6c  6f 67 5f 6f 75 74 64 65  |e......log_outde|
00004570  6e 74 28 6c 25 29 0d 14  a0 16 f4 20 58 53 79 73  |nt(l%)..... XSys|
00004580  4c 6f 67 5f 55 6e 49 6e  64 65 6e 74 0d 14 aa 2e  |Log_UnIndent....|
00004590  e7 20 6c 25 3c 3e 2d 31  20 8c c8 99 20 26 36 43  |. l%<>-1 ... &6C|
000045a0  38 38 36 2c 6c 25 20 8b  c8 99 20 26 36 43 38 38  |886,l% ... &6C88|
000045b0  36 2c 41 70 70 6e 61 6d  65 24 0d 14 b4 05 e1 0d  |6,Appname$......|
000045c0  14 be 05 3a 0d 14 c8 25  f4 20 50 52 4f 43 6c 6f  |...:...%. PROClo|
000045d0  67 5f 64 61 74 61 20 3a  20 4c 6f 67 20 61 20 64  |g_data : Log a d|
000045e0  61 74 61 20 62 6c 6f 63  6b 0d 14 d2 22 dd f2 6c  |ata block..."..l|
000045f0  6f 67 5f 64 61 74 61 28  6c 6f 67 25 2c 6c 25 2c  |og_data(log%,l%,|
00004600  64 25 2c 6c 65 6e 25 2c  62 25 29 0d 14 dc 15 f4  |d%,len%,b%).....|
00004610  20 58 53 79 73 4c 6f 67  5f 4c 6f 67 44 61 74 61  | XSysLog_LogData|
00004620  0d 14 e6 4e e7 20 6c 6f  67 25 3c 3e 2d 31 20 8c  |...N. log%<>-1 .|
00004630  c8 99 20 26 36 43 38 38  41 2c 6c 6f 67 25 2c 6c  |.. &6C88A,log%,l|
00004640  25 2c 64 25 2c 6c 65 6e  25 2c 62 25 20 8b c8 99  |%,d%,len%,b% ...|
00004650  20 26 36 43 38 38 41 2c  41 70 70 6e 61 6d 65 24  | &6C88A,Appname$|
00004660  2c 6c 25 2c 64 25 2c 6c  65 6e 25 2c 62 25 0d 14  |,l%,d%,len%,b%..|
00004670  f0 05 e1 0d ff                                    |.....|
00004675