TITLE TCPSER

;;; This program is loaded by the system when a SYN is received for
;;; a legal service port (0-777) and there is no LISTEN for it.

	A=1
	B=2
	C=3
	D=4
	E=5

	DSKI==1			; Channel for loading server.

DEBUG:	0			; -1 => Debug mode.
REQ:	0			; Holds request

GO:	.CALL [ SETZ		; Get a pending RFC.
		SIXBIT /NETRFC/
		MOVE [SIXBIT /TCP/]
		SETZM REQ]
	 JSR LOGOUT		; None or error.
	HRRZ A,REQ		; Get RH = port #
	CAILE A,777		; Make sure it's okay
	 JRST REFUSE
	REPEAT 3,[
		LSHC A,-3
		LSH B,-3
		]
	HLRZ D,B
	ADD D,[SIXBIT /SYN000/]

ENDLUP:	MOVE 0,D		; Contact name, sixbitified, is passed in AC0
	.SUSET [.SSNAME,,D]	; Also pass it in the sname, for debugging
	.CALL [	SETZ		; Open DEVICE;TCP SYNnnn
		SIXBIT /OPEN/
		[.UII,,DSKI]
		[SIXBIT /DSK/]
		[SIXBIT /TCP/]
		D
		SETZ [SIXBIT /DEVICE/]]
	 JRST REFUSE		; Lose, no such server.
	MOVE 17,[ACBLK,,1]	; Load it in and start it.
	BLT 17,ACBLKL
	JRST 1

ACBLK:	.CORE 0			;1  - vital to clear core!!
	 .LOSE			;2
	.CALL 10		;3
	 .LOGOUT 1,		;4
	.IOT DSKI,17		;5
	.CLOSE DSKI,		;6
	JRST (17)		;7
	SETZ			;10
	SIXBIT /LOAD/		;11
	MOVEI %JSELF		;12
	SETZI DSKI		;13
ACBLKL=.-ACBLK

IFNDEF %NQREF,%NQREF==1
REFUSE:	.CALL [SETZ ? SIXBIT /NETRFC/ ? %CLBIT,,%NQREF
		MOVE [SIXBIT /TCP/]
		SETZ REQ]
	 JSR LOGOUT
	JRST DONE

LOGOUT:	0
	SKIPE DEBUG
	 .VALUE
DONE:	.LOGOUT 1,

	END GO
