View previous topic :: View next topic |
Author |
Message |
rd
Joined: 13 Sep 2002 Posts: 9254 Location: Jacksonville, FL
|
Posted: Fri Sep 11, 2009 4:09 am Post subject: rdwrites HELLOPARMS CGIDEV2 parm info demo |
|
|
Here's a CGIDEV2 parm handling demo I just wrote, HELLOPARMS. It's the first step to an HELLOWORLD as I get my feet wet.
http://code.google.com/p/rdwrites/downloads/list
The download is helloparms.zip
Everything in this can be found in CGIDEV2's TEMPLATE5 demo.
I didn't do anything fancy concerning looking for parms. I just look for two parms called mode and count as in:
iseries_url/helloparms?mode=visitors&count=32000
This is my first CGIDEV2 web page. The basics of putting out an RPG CGIDEV2 web page are lightning fast, development and execution.
HELLOPARMS can be run on my server with http://173.8.38.42:2700/iseries/helloparms?mode=visitors&count=32000
(mode and count can be given any values or one or both dropped off the URL as parms and resubmitted from the Go bar)
The HELLOPARMS CGIDEV2 demo source code can be viewed below. I will be releasing hopefully more interesting and useful stuff as I go along.
I want to add my vote of thanks to the CGIDEV2 team and to the IBM RPG compiler developers. I am continually surprised and pleased at the power of the RPG language and API's and now more so with the CGIDEV2 interface, and that's directly attributable to the above mentioned people.
rd |
|
Back to top |
|
 |
rd
Joined: 13 Sep 2002 Posts: 9254 Location: Jacksonville, FL
|
Posted: Fri Sep 11, 2009 4:10 am Post subject: |
|
|
Code: |
*****************************************************************
* CGIDEV2 Testing
*
* Program HELLOPARMS
*****************************************************************
*****************************************************************
* Prototype Definitions
*****************************************************************
h dftactgrp(*no) actgrp('HELLOPARMS')
/copy rdwsrc,CGIDEV2PR
*****************************************************************
* *Entry Declaration
*****************************************************************
d HELLOPARMS pr
d HELLOPARMS pi
*****************************************************************
* Data Structure Declaration
*****************************************************************
*****************************************************************
* Stand Alone Fields Declaration
*****************************************************************
d HELLOPARMSttl c 'HELLOPARMS Parm Diagnostics'
*****************************************************************
* Mainline
*****************************************************************
/free
exsr initProgram;
// read externally defined output html files
IfsMultIndicators = gethtmlifsmult('' +
CGIDev2Html + 'stdtop.html ' +
CGIDev2Html + 'stdmsg.html ' +
CGIDev2Html + 'stdruntime.html ' +
CGIDev2Html + 'stdend.html' + ''
:'<as400>');
// output HTML message if fail to load HTML templates and exit
if NoErrors = *off;
exsr failLoadHtml;
exsr exitProgram;
endif;
// output web page with parms data
updHtmlVar('title':HELLOPARMSttl);
wrtSection('top');
addMsg('REQUEST_METHOD = ' + getEnv('REQUEST_METHOD':qusec));
addMsg('HTTP_REFERER = ' + getEnv('HTTP_REFERER':qusec));
addMsg('REMOTE_ADDR = ' + getEnv('REMOTE_ADDR':qusec));
wrtMsgs();
// get input
nbrVars = zhbGetInput(savedQueryString:qusec);
clrMsgs();
addMsg('Number parms = ' + %char(nbrVars));
addMsg('mode = ' + zhbGetVar('mode'));
addMsg('count = ' + zhbGetVar('count'));
wrtMsgs();
// get and write run time
updHtmlVar('runtime':%editc(timerElapsed():'N'));
wrtSection('runtime');
// complete send of buffered output to the browser
wrtSection('endhtml *fini');
// exit program
exsr exitProgram;
//**************************************************************
// Subroutine: failLoadHtml
//**************************************************************
begsr failLoadHtml;
wrtDebug('' + pgmname + ': IfsMultIndicators = ' +
IfsMultIndicators + '');
// send psds data to cgidebug physical file
wrtPSDS(psds);
htmlMsgStr = htmlHeader + newline + newline + htmlErrMsg;
wrtNoSection(%addr(htmlMsgStr)+2:
%len(htmlMsgStr));
wrtSection('*fini');
endsr;
//**************************************************************
// Subroutine: exitProgram
//**************************************************************
begsr exitProgram;
// strategy is to exit with LR on in this diagnostic program
*inlr = *on;
return;
endsr;
//**************************************************************
// Subroutine: initProgram
//**************************************************************
begsr initProgram;
// Get program start time for calculating execution time
timerStart();
// clear messages
clrMsgs();
doCmd('ADDLIBLE ' + CGIDev2Lib + ' *LAST');
setNoDebug(*off); // *off to support diagnostics
// Write qualified job name to debug file.
wrtJobDbg(*on);
// clear the HTML buffer
if getHtmlBytesBuffered > 0;
clrHtmlBuffer();
endif;
endsr;
/end-free
|
|
|
Back to top |
|
 |
rd
Joined: 13 Sep 2002 Posts: 9254 Location: Jacksonville, FL
|
Posted: Fri Sep 11, 2009 4:15 am Post subject: |
|
|
Code: |
*****************************************************************
* CGIDEV2 Prototype Definitions
*
* Copy file CGIDEV2PR
*****************************************************************
* H specs
h bnddir('CGIDEV2':'QC2LE':'QUSAPIBD')
h optimize(*NONE) decedit(*JOBRUN) truncnbr(*NO)
h debug option(*srcstmt:*nodebugio)
* D specs
/copy cgidev2/qrpglesrc,prototypeb
*****************************************************************
* Data Structure Declaration
*****************************************************************
* system program feedback area
d psds sds 429
d pgmname 10a
d pgmlib 81 90a
d jobname 244 253a
d usrname 10a
d jobnbr 6s 0
d qusec ds
d qusbprv like(int32) inz(%size(qusec))
d qusbavl like(int32) inz(0)
d qusei 7a
d 1a
d msgdata 500a
* indicators for getHtmlIfsMult subprocedure
d IfsMultIndicators...
d ds
d NoErrors like(boolean)
d NameTooLong like(boolean)
d NotAccessible like(boolean)
d NoFilesUsable like(boolean)
d DupSections like(boolean)
d FileIsEmpty like(boolean)
*****************************************************************
* Stand Alone Fields Declaration
*****************************************************************
* like prototypes
d boolean s n
d int32 s 10i 0
* program timing variable
d sec s 15p 6
* number of variables
d nbrVars s like(int32)
* string variables
d htmlMsgStr s 1000 varying
d savedQueryString...
d s 32767 varying
* constants
d newline c const(X'15')
d CGIDev2Lib c 'CGIDEV2'
d CGIDev2Html c '/CgidevExtHtml/'
d htmlHeader c 'Content-type: text/html'
d htmlErrMsg c '<html><body> -
d <p>An error occurred. -
d Programmer has been notified. -
d Please try again later. -
d </p></body></html>'
|
|
|
Back to top |
|
 |
rd
Joined: 13 Sep 2002 Posts: 9254 Location: Jacksonville, FL
|
Posted: Wed Jun 15, 2011 8:19 pm Post subject: |
|
|
a poster wrote: On some rare occasions my CGIDEV2 program crashes in the WRTSECTION module when performing CLRHTMLBUFFER with the message:
The pointer parameter passed to free or realloc is not valid.
I took a quick look at the CGIDEV2 code (XXXWRKHTML in QRPGLESRC) and can offer a couple of comments in lieu of Giovonni or someone else knowledgeable on it has time to reply.
The specific line that fails is a realloc of memory if buffer size exceeds initial alloc of 100,000 bytes. The buffer pointer is set in InitHTML and when STDOUT is done. My guess is this is triggered under some possibly rare condition where the buffer accumulates a lot of data and no output is done with it. The extreme case of this is if buffer exceeds 16 MB, the code says it will crash. But I'm thinking more of something getting out of synch when no STDOUT's are done with data exceeding ~100k. (wrtBuffer, wrtSection, etc.)
I compared to my use of clrHtmlBuffer and use of wrtSection in my small demo program HelloParms in Google Code project rdwrites. I conditioned the clear buffer with a check if anything was in the buffer which eliminates an unnecessary buffer reset (although if less than 100k looks like it's next to no code executes) and cuts down on accessing an invalid buffer (the assumption being that it is more likely to be valid with a counter saying there is something in it, as in:
// clear the HTML buffer
if getHtmlBytesBuffered > 0;
clrHtmlBuffer();
endif;
The other point is that I don't clear the buffer before each wrtSection, just once upon entry. It seems to me that just letting the (pretty complex) code do its thing and reset pointers etc is the way to go. Clear buffer is only necessary if a previous process ended abnormally leaving the buffer unflushed.
This at least gets me thinking about this stuff. I am trying to make time to take next step on it. I know a little bit more now than I did before your question.
rd |
|
Back to top |
|
 |
|