C
C	Test hpss library.
C
C	/mailbox=xxx
C	/accept_timeout=n
C	/response=(linessize,lines)
C	/flush_policy=(all,header,disconnect)
C
	PROGRAM TEST_HPSS
C
	IMPLICIT NONE
	INTEGER HPSS_INITIALIZE, HPSS_ACCEPT, STATUS, CONTEXT, PID
	INTEGER HPSS_DISCONNECT, HPSS_GETENV, HPSS_WRITE, ILEN
	INTEGER HPSS_READ, HPSS_GETFORM
	INTEGER SYS$HIBER, SN_LEN, I
	CHARACTER FUNC*32, VALUE*256, SERVER_NAME*256, INPUT*1024
C
	STATUS = HPSS_INITIALIZE ( 'HPSS_srv_test', 1, CONTEXT )
	IF ( .NOT. STATUS ) TYPE*,
	1	'Status of web init and context:', STATUS, CONTEXT
	DO WHILE ( STATUS )
	    STATUS = HPSS_ACCEPT ( CONTEXT, 30, PID, FUNC )
	    TYPE*,'Accept status:', STATUS, PID, '  func: ', FUNC
	    IF ( STATUS ) THEN
		!STATUS = HPSS_READ ( CONTEXT, INPUT, ILEN )
		!IF ( STATUS ) THEN
		!    TYPE*,'Content read, len:', ILEN
		!    !TYPE*,'"', INPUT(:ILEN),'"'
		!ELSE
		!    TYPE*,'Error reading content:', STATUS
		!END IF
		STATUS = HPSS_GETFORM ( CONTEXT, 'address', INPUT, ILEN )
		TYPE*,'Status of address get: ', STATUS, ILEN
		IF ( STATUS ) TYPE*,'value: "', INPUT(:ILEN),'"'

		STATUS = HPSS_GETENV ( CONTEXT,
	1		'SERVER_NAME', SERVER_NAME, SN_LEN)
		!TYPE*,'getenv status:', STATUS, SN_LEN 
		!TYPE*,'   server_name: "', SERVER_NAME(:SN_LEN),'"'

		STATUS = HPSS_WRITE ( CONTEXT, 'Content-type: text/plain',
	1		1 )
		STATUS = HPSS_WRITE ( CONTEXT, 
	1		CHAR(13)//CHAR(10)//'Dummy data ', 0)  ! 39
		DO I = 1, 3000
		    STATUS = HPSS_WRITE ( CONTEXT,
	1		'a                                               z', 1)
		    IF ( .NOT. STATUS ) GOTO 300
		END DO
300		STATUS = HPSS_WRITE ( CONTEXT, '  end of line (with no flsh)', 
	1		1 )
		IF ( .NOT. STATUS) TYPE*,'Status of last write:', STATUS
	    ENDIF
	    STATUS = HPSS_DISCONNECT ( CONTEXT )
	    IF ( .NOT. STATUS) TYPE*,'Status of disconnect:', STATUS
	    STATUS = 1
	END DO
	END
