From: Rob McCool
Newsgroups: netscape.devs-nsapi
Subject: Re: NSAPI is inferior. Here is one simple example.
Date: Fri, 07 Feb 1997 18:04:14 -0800
Ted Giesel wrote:
>
> 02/02/97
>
> As an expert in the field of C/C++, server architectures, and fault
> tolerant systems, I have been asked to evaluate NSAPI versus ISAPI.
>
> My very first program, a simple service function, clearly shows serious
> threading issues with the Fasttract server and Enterprise server (2.01)
> on an Intel processor.
>
> This function runs perfectly under Microsoft's IIS when compiled to the
> ISAPI libraries.
>
> The purpose of the function is to return a portion of a chosen file as
> the content reply. It works fine until one makes multiple requests to a
> frameset. The content of each frame should be identical, but instead it
> is returned corrupted.
>
> The HTML, source, and a content.txt file for your convenience have been
> included. The make file for VC++ 4.2 is also attached.
>
> Netscape should be embarrassed by this glaring error. I recommend
> increasing your QA effort.
>
> -Ted Giesel
> Senior Programmer
>
>
> ---------------------------------------------------
> The HTML, which loads the frameset, is given below:
>
>
>
> Four Identical Frames?
>
>
>
>
>
>
> ---------------------------------------------------
> The source code is as follows:
>
> #include "base/pblock.h"
> #include "base/session.h"
> #include "frame/req.h"
>
> #include "frame/protocol.h"
> #include "frame/log.h"
>
> #define FNAME "C:\\content.txt"
> #define FSIZE "5000"
>
> NSAPI_PUBLIC int serv_content(pblock *pb, Session *sn, Request *rq)
> {
> char* FileName = FNAME;
> char* ServSize = FSIZE;
> int iServSize;
> SYS_FILE content;
>
> char* ch = "A";
Why are you initializing this variable this way instead of creating a
local variable on the stack like "char ch[1]"? The storage for the
string "A" is not thread-local in this case, so whether or not you can
get away with doing a write into this location followed by a read
without having threads race is very tricky.
The semantics of what you are doing here are very compiler dependent,
and whether or not you can get away with doing this in a threaded
environment are very dependent on the thread scheduling policy of the
operating system and application. I suspect that the reason that you do
not see this in IIS is due to the differences in the way they schedule
their threads and I/O.
The reason why Mike Shaver got 5000 "A"'s in his windows is because by
default, most UNIX compilers leave a program's shared text region
read-only. I'm reasonably certain that NT leaves it read-write by
default, but that does not change the fact that there is only one
location being changed here.
Can you please change this line to char ch[1]; and try your test again?
> int sent = 0;
> int i;
>
>
> content = system_fopenRO(FileName);
> while(content == NULL) {
> content = system_fopenRO(FileName);
> }
>
> param_free(pblock_remove("content-type", rq->srvhdrs));
> pblock_nvinsert("content-type", "text/html", rq->srvhdrs);
>
> param_free(pblock_remove("content-length", rq->srvhdrs));
> pblock_nvinsert("content-length", ServSize, rq->srvhdrs);
>
> protocol_status(sn, rq, PROTOCOL_OK, NULL);
> protocol_start_response(sn, rq);
>
> iServSize = atoi(ServSize);
>
> for(i=0; i system_fread(content, ch, 1);
>
> sent = net_write(sn->csd, ch, 1);
> while(sent == 0) {
> sent = net_write(sn->csd, ch, 1);
> }
> }
> system_fclose(content);
>
> return REQ_PROCEED;
> }
--
Rob McCool, robm@netscape.com http://home.netscape.com/people/robm/
Stunt Programmer, Netscape Communications Corporation
It was working ten minutes ago, I swear...
Reproduced by permission of the author.