|
very very thank you sir.
Regards,
Vishal
|
|
|
|
|
I'm busy with my own http server implementation on an embedded platform. Technically the server is HTTP 1.0 compliant, and therefore it expects the the client to send the header "Connection: Keep-Alive" to keep the connection open.
The implementation looks like this. I removed the code that parses the HTTP header and performs the request, to keep the post as short as possible:
int Service_Request(int conn) {
struct ReqInfo reqinfo;
volatile int resource = 0;
int retval = 0;
Req_Result req_result = GOT_REQ;
InitReqInfo(&reqinfo);
while (req_result == GOT_REQ)
{
req_result = Get_Request(conn, &reqinfo);
if ( req_result == TIMEOUT_REQ)
{
retval = 0;
break;
}
else if (req_result == ERROR_REQ)
{
retval = -1;
break;
}
if (reqinfo.method == GET)
{
}
else if ((reqinfo.method == PUT) || (reqinfo.method == POST) )
{
}
else
{
reqinfo.status = 501;
Return_Error_Msg(conn, &reqinfo);
}
if(reqinfo.keep_alive == 0)
{
break;
}
reqinfo.keep_alive_max--;
if(reqinfo.keep_alive_max <= 0 )
{
break;
}
Writeline(conn,"\r\n",2);
FreeReqInfo(&reqinfo);
}
FreeReqInfo(&reqinfo);
return (retval);
}
The Get_Request function looks like this:
Req_Result Get_Request(int conn, struct ReqInfo * reqinfo) {
char buffer[MAX_REQ_LINE] = {0};
int rval;
fd_set fds;
struct timeval tv;
if(reqinfo->first_request == 1)
{
tv.tv_sec = 5;
tv.tv_usec = 0;
reqinfo->first_request = 0;
}
else
{
tv.tv_sec = reqinfo->keep_alive_timeout;
tv.tv_usec = 0;
}
do {
FD_ZERO(&fds);
FD_SET (conn, &fds);
rval = select(conn + 1, &fds, NULL, NULL, &tv);
if ( rval < 0 )
{
Diag_Msg("Error calling select() in get_request()");
return (ERROR_REQ);
}
else if ( rval == 0 ) {
return (TIMEOUT_REQ);
}
else {
memset(buffer,0,MAX_REQ_LINE - 1);
if(Readline(conn, buffer, MAX_REQ_LINE - 1) == -1)
{
return (ERROR_REQ);
}
if(reqinfo->clientRequest == NULL)
{
reqinfo->clientRequest = calloc(MAX_REQ_LINE - 1, sizeof(char));
strncpy(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
}
else
{
strncat(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
}
Trim(buffer);
if ( buffer[0] == '\0' )
break;
if ( Parse_HTTP_Header(buffer, reqinfo) )
break;
}
} while ( reqinfo->type != SIMPLE );
return (GOT_REQ);
}
To describe the workings of this server in English: The server receives the first request. It parses the headers, if it finds the "Connection: Keep-Alive" header, it sets a flag. The server proceeds to process this request. WHen it is done it checks the keep-alive flag. If it is cleared, the server closes the connection. If set the server performs a clean-up operation and the proceeds to wait for another request over the same connection. And so on.
I tested this with curl:
C:\curl>curl -v -H "Connection: Keep-Alive" --data-binary ( at )vid1.bin 10.84.67.129/s1p0:1/vid[1-2].bin
[1/2]: 10.84.67.129/s1p0:1/vid1.bin --> <stdout>
--_curl_--10.84.67.129/s1p0:1/vid1.bin
* About to connect() to 10.84.67.129 port 80 (#0)
* Trying 10.84.67.129...
* connected
* Connected to 10.84.67.129 (10.84.67.129) port 80 (#0)
> POST /s1p0:1/vid1.bin HTTP/1.1
> User-Agent: curl/7.28.1
> Host: 10.84.67.129
> Accept: **
> Connection: Keep-Alive
> Content-Length: 51200
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
* HTTP 1.0, assume close after body
< HTTP/1.0 100 Continue
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: DTSVU v0.1
< Content-Type: text/html
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Keep-Alive: timeout=5, max=10
<
* Connection #0 to host 10.84.67.129 left intact
* Closing connection #
As you can see, curl says: Connection #0 seems to be dead! after the first request is completed. It then proceeds to close the connection and opens a new one. I'm sure I implemented the HTTP 1.0 keep-alive functionality correctly. SO my question is: what does curl expect over the connection after the first request is completed? Why does it decide the connection is dead?
PS the above code was adapted from http://www.paulgriffiths.net/program/c/webserv.php
|
|
|
|
|
This does not really have anything to do with C/C++; you may get a better response in the Web Development forum[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Sorry about about posting in the wrong forum. Could a moderator please move it?
I solved it myself. If the server replies with HTTP/1.1 and "Content-Length: 0", curl reuses the connection. My server reply lookes like this
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: DTSVU v0.1
Content-Type: text/html
Connection: Keep-Alive
Keep-Alive: timeout=1, max=95
Content-Length: 0
after the 5th reuse of the connection.
|
|
|
|
|
Hi
I'm having trouble trying to load a non-default .wab file (I know it's old hat but need to keep it going for my XP users). I'm running it on Vista and although I'm supplying a filename it keeps loading my Vista Contacts instead instead of the specific wab addresses.
It must be going wrong around here (mostly stock code from the msdn sample code):
// (pszFileName is const char *)
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
if(m_lpfnWABOpen)
{
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName;
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
if(m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0)==S_OK)
m_bInitialized = TRUE;
}
As usual, any help much appreciated.
Greg
|
|
|
|
|
Why is this conversion needed:
Member 868926 wrote: wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName; ?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Good point, well I'm now trying:
wp.szFileName = "C:\\Jim.wab";
as I know that wab exists there but it still isn't loading it.
G
|
|
|
|
|
Are you completely sure that is a correct WAB file and it is readable by the process (it has the required access rights and somesuch)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Yes the wab is OK. If you doubleclick it Windows asks if you want to import the addresses.
Somehow the WabOpen bit just thinks I want the default Wab (although there isn't one in Vista) and isn't getting the filename. In the original code there was a 'GetNativePath()' call which isn't available - could it be to do with how I'm passing in the file location string?
G
|
|
|
|
|
As far as i remember the documentation says it will load the default if you pass NULL for the path, but you are not passing NULL but a seemingly correct path. Hmm...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
If i check the documentation (http://msdn.microsoft.com/en-us/library/ms629458%28v=vs.85%29.aspx[^]) for WAB_PARAM , the szFileName member is declared to be LPTSTR . This suggests that depending on your target options, it might be a unicode or an ansii/mbcs string which then suggests that there might be a unicode and an ansii/mbcs version of the function (as with a lot of API methods throughout windows). When you query the function's pointer...are you sure you are getting the correct version?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I'm not sure - in the header file I can't see another version except WabOpenEx which I tried but didn't work.
I've noticed that my Contacts folder is actually receiving the wab addresses and getting bigger and bigger! So instead of opening the wab on its own it's adding them to the Contacts then opening those instead. Is this some undocumented Vista mechanism?
Thanks very much for everyone's conttributions so far.
G
|
|
|
|
|
Frankly, i don't know, sorry...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
- Have you checked the actual error code returned from the
WABOpen Function? - Have you checked the documentation[^] for compatibility?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
It doesn't return an error, just loads my Vista Contacts instead. Compatability seems OK.
|
|
|
|
|
Have you tried removing the default contacts file to see if it works then? It's a long while since I used WAB and I never actually tried using the non-default file.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I tried that, then it just doesn't load anything.
|
|
|
|
|
Sorry, I cannot think of anything else to suggest. You could try the Microsoft forums.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I have the following code:
FILE *fp = stdin;
if ((fp = fopen(argv[optind], "rb")) == NULL) {
printf("Cannot open file %s\n", argv[optind]);
return 2;
}
It executes correctly and the correct file is accessed.
I added the following to get the file size:
SizeLow = GetFileSize(_fileno(fp), & SizeHigh);
if ((SizeLow == 0xFFFFFFFF) && ((Error = GetLastError()) != NO_ERROR)) {
printf("Cannot read file size for %s, error %d\n", argv[optind], Error);
help();
return 2;
}
if (binary && (SizeHigh > 0x70000000)) {
printf("File too big for Binary Mode\n");
help();
return 2;
}
__asm {
mov eax,SizeLow
mov edx,SizeHigh
cmp binary,TRUE
jnz Bytes
shld edx,eax,3
shl eax,3
Bytes:
mov DWORD PTR totalc,eax
mov DWORD PTR totalc+4,edx
}
When I execute I get the following:
ent.exe f:\tst1.tst >ent1.txt
Cannot read file size for f:\tst1.tst, error 6
What am I doing wrong with the the GetFileSize call?
In case you are wondering, this is a modification to John Walker's ENT to speed up execution for huge files.
Dave.
|
|
|
|
|
GetFileSize() expects a file HANDLE but you are passing a file descriptor returned by _fileno() . This is indicated by the error code 6 ERROR_INVALID_HANDLE .
See A Handy Guide To Handling Handles[^] for the differences and how to convert between the various file handle types.
|
|
|
|
|
Jochen,
Thank you for the excellent reference. Just what I needed.
Dave.
|
|
|
|
|
Jochen,
With this line, everything works correctly:
SizeLow = GetFileSize(_get_osfhandle(_fileno(fp)), & SizeHigh);
Thanks for the pointer.
Dave.
|
|
|
|
|
Hi
While launching a MFC application(.exe) as OLE server, some time CWinApp::OnFileNew() gets failed; due to this frame window cannot be created and handle to the main window (m_pMainWnd) becomes NULL and error message "Error occurs in mfc42.dll" appeared.
At windows XP, CWinApp::OnFileNew() failed in 1 out of 100 times.
We have not implemented the OnFileNew() in our application; we are using default implementation of OnFileNew().
As per MSDN CWinApp::OnFileNew implements this command differently depending on the number of document templates in the application. If there is only one CDocTemplate, CWinApp::OnFileNew will create a new document of that type, as well as the proper frame and view class.
Problem occurs only at one system and frequency is one out of 100 and error message "Error occurs in mfc42.dll" appeared.
Thank You
Ashish Kumar verma
Software Engineer(VC++)
|
|
|
|
|
From your information it is rather impossible to guess what is wrong. But I will give you some notes that may help you to find the problem or enhance your question:
"Error occurs in mfc42.dll" seems to be an application specific error message (googling the exact term gives only a few results). So you should be able to locate the executed source sections before the error occurs.
Even when using the default implementation of OnFileNew() , virtual functions of your document class are involved. In this case I would especially check OnNewDocument() . When this returns FALSE , creation of the document and frame window will be stopped (see the MFC sources for CSingleDocTemplate::OpenDocumentFile() ).
|
|
|
|
|
I ran into a small problem using Visual Studio 2012 Update 1.
Any MFC dialog that has controls with icons or bitmaps does not show the graphics if it is the first one in z-order. The following controls are displayed correctly.
A simple way to demonstrate this bogus behavior is to generate a dialog application with a couple of MFC EditBrowse Controls (but you could use MFC Buttons with icons as well). You can arbitratily change the z-order of the controls with the result that the icon does not display for the first one (preview is ok but not the compiled application).
I don't know whether this problem occurs in other versions of VS or if I have overlooked something important like proper initialization.
A simple way to get around this problem is to add a control with a picture at z-order 1 and make it invisible such that subsequent controls are not affected.
Has anybody dealt with this before?
_jg_
|
|
|
|