|
Hi,
my named-pipe experience is limited, but I have some questions/ideas anyway:
- does it fail completely (all subsequent clients get no service) once it starts to fail?
- how many connections succeed before it fails the first time? 25? much more?
- how many clients did terminate abnormally before it started to fail? around 25?
I mean: maybe you are debugging the client and abort it, rather than let it finish and
close the handles and thing like that.
- you should consider adding some logging in the server (and the clients) so you can see
what is the first thing that fails, when it is, and possibly show error messages
from GetLastError() and such.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc! thanks for the reply!
yes, once it fails, it fails completely. no more CreateFile call is successful.
i am not sure how many successful connection were made. there was a lot since i was running it for a few hours already and every 1 minute i am sending some data.
no clients so far based on the logging terminated abonormally.
though i noticed in the logging that there was a concurrent call to CreatFile then it started to fail.
that is why i am asking what the effect is if 2 concurrent calls to CreateFile was made on the same pipe server.
thanks so much!
old
|
|
|
|
|
ginjikun wrote: there was a concurrent call to CreatFile then it started to fail
not sure what you mean here. is it two clients trying to each use a pipe at the same time?
if so, any chance that was the first time two pipes would be active together? (that would
point to some design/implementation error in the server I guess).
PS: I will be off pretty soon. You may get more help by posting more detailed description
of good operations, symptoms for bad operation, and showing more code.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi again Luc! and thanks again for the reply.
what i mean by concurrent call to CreateFile was that there was 2 calls to the functions i have created which calls CreateFile. i have a DLL which have exported functions for sending data.
sample code is... in my DLL
function1()
{
Log("function1 Entry");
CreateFile(..);
WriteFile(..);
ReadFile(..);
CloseHandle(..);
Log("function1 Exit");
}
there is no lock in function1. in the logging i saw
"function1 Entry"
"function1 Entry"
which means that 2 calls to this function was made even before the 1st call has finished. ideally that log should be like this
"function1 Entry"
"function1 Exit"
"function1 Entry"
"function1 Exit"
after i saw the log which have 2 entries "function1 Entry" then all succeeding logs was the failed in CreateFile. maybe the issue is not the concurrent call to CreateFile but it is in the function whereby the first call has connected already then another calls CreateFile again. will this invalidated the pipe instance previously created? i guess another question should be what if a function was called concurrently when it has not yet finished its previous processing, what will be the effect?
im lost
thanks for the help!
old
|
|
|
|
|
ginjikun wrote: i'm lost
to the contrary, you are zeroing in on the problem.
does your client code have full error checking?
every call related to pipes should check its return value, and whenever it is not good,
it should call GetLastError and log the result. That will tell you what goes wrong there
as soon as things start to go wrong.
chances are you will have to provide a lock over the entire function1.
Q: if function1 uses some variables that are not local, should they be common to all the
threads that may be running at once, or should they be local to the thread?
depending on the answer, if there are global variables, you may have to store them as
real globals or as thread-specific data (or whatever it is called).
That's it for today. Good luck.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hey Luc!
thanks!
yes it does. it checks for errors everywhere and it calls GetLastError to log the error encountered. i have tried to add locking in function1 and have left it running for over 2 hours now. so far it is still running!
no global variables are used. all are local variables which are parameters. ooopss forgot to mention function1 takes the parameters pipename (complete with machine to connect) and the data to be sent.
function1(pipename, data)
i am still lost as how exported functions behave. is it blocking? if it has no locking and was called at the same time (almost the same time ) what will happen?
thanks! thanks!
old
|
|
|
|
|
Hi,
you're welcome.
ginjikun wrote: left it running for over 2 hours
you could get more testing done by decreasing the time in between communications; just
for testing purposes reduce the period from 1 minute to 10 seconds, or 1 second. That way
a 1 hour run simulates an actual run of 6 or 60 hours...
ginjikun wrote: how exported functions behave. is it blocking?
is several threads of the same process, or some threads of different processes, call
the same function in a (shared) DLL, then they will run any way they see fit, there is
no automatic blocking, locking, synchronization, whatever; so either your code must
be "thread-safe" (i.e. withstand such concurrent execution), or explicit locking must
be provided.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
It would be helpful if you could paste more detail of the code instead of just the summary. In that function the "function1 Exit" was not printed for both those concurrent calls ?
|
|
|
|
|
Hi Llasus!
the "function1 exit" was printed after it encountered the error "The system cannot find the file specified.".
function1 called is just like as i have posted it less the checking and the other function calls like PeekNamedPipe to avoid cluter. it just calls CreateFile if successful then calls WriteFile and then calls ReadFile then CloseHandle. but in CreateFile it already fails
function1(pipename, data)
{
if(CreateFile(pipename...))
{
WriteFile(data...);
ReadFile(reply...);
Closehandle(...);
}
else
{
Log(GetLastError());
}
}
thanks again!
old
|
|
|
|
|
The code is too little to somehow point-out where the problem can be. Paste more of your codes. As far as I can guess, since it had successfully operated for an hour and failed after that, it seems that at some point some pipes wasn't released/closed properly which caused other clients to be unable to access the server (reached max 25 connections) and thus fails the CreateFile. Double check all the CloseHandle and DisconnectNamedPipe and make sure that your applications go to those part after using it. You can also paste more of your codes so that we can analyze it more.
|
|
|
|
|
Hi Llasus! thanks!
i have added some code in my latest reply to Luc. please refer to that one.
i have checked the log file and have so far found no failure in the releasing of the named pipe connection. also, if ever there are no more instances for the pipe to connect to, shouldnt the error be pipe busy or something similar to that? from the description
"The system cannot find the file specified." what i understand is that it is trying to connect to something which does not exist. i am not sure though
thanks for the help!
old
|
|
|
|
|
In that sample which you have pasted, in that function the "function1 Exit" was not printed for both those concurrent calls?
|
|
|
|
|
Hi Llasus!
the "function1 exit" was printed after it encountered the error "The system cannot find the file specified.".
function1 called is just like as i have posted it less the checking and the other function calls like PeekNamedPipe to avoid cluter. it just calls CreateFile if successful then calls WriteFile and then calls ReadFile then CloseHandle. but in CreateFile it already fails
function1(pipename, data)
{
if(CreateFile(pipename...))
{
WriteFile(data...);
ReadFile(reply...);
Closehandle(...);
}
else
{
Log(GetLastError());
}
}
thanks again!
old
|
|
|
|
|
ginjikun wrote:
the "function1 exit" was printed after it encountered the error "The system cannot find the file specified.".
If that's the case, since the client seems to close the pipes successfully after each use, then let's look at your server code. I checked the for loop of that code, after the ConnectNamedPipes() are the next set of codes inside the same for loop? or is it set within a separate thread for every ConnectNamedPipes()?
|
|
|
|
|
I'm new in Window API,I'm able to take handle and put target program SCR in front and able to capture Title. I would like to capture content chars of Client-Area. I'm using AS/400 terminal emulator which use TELNET to communicate with AS/400. I need to know which SCR, user is using now so that I am able to judge whether my other program can activate or not.
There is screen to measure weight and to measure total weight. When user press F3 on the screen, I capture weight from weighing machine, when user press F6 on the screen, I summarize weight and put it to keyboard buffer.
Problem is I don't know which screen user is using so that whenever user press F3, PC program get weight from weighing machine. To prevent it, I must know which screen user is using, in case of different screen I don't activate PC program.
|
|
|
|
|
Capture TEXT mean
Say for example, I have NotePad to which I have type some chars.
I look for "PACKAGE Weight:" inside chars.
If I find it, this is SCREEN what I want(F3=capture weight).
I look for "Total Weight:" inside chars, that is the SCREEN what I want (F6
=summarize weight)
So how do I get SOME CHARS from NotePad using API ?
AS/400 screen, still same I believe (I can copy -> paste to NotePad
and it is not IMAGE, chars, I can copy it)
|
|
|
|
|
Hi all. Im going to try my best in explaining on what i need. I have a program that downloads an update to the package. I havnt gotten so good that i can update the file with out stopping or closing it but this is the only solution i could come up with. In order for the new program to work the old one has to download it. Then open it. I used ShellExecute() to open the new program. Thats not the problem though. Well now that i have the new program in the install folder, i need to kick the old one. So what im trying to do is get it to delete any files that opened it. I'll make a brief description.
<quote>
old-file.exe opens new-file.exe
new-file.exe starts up and deletes old-file.exe
I cant make it any simple than that. I thought by using argv that would be a start in figuring it out but i dont know how. Any suggestions? Thanx in advance!
|
|
|
|
|
Using VC++2005, created a Windows Forms Application.
On the click of a button I execute a method from another class which takes a long time to process. Part of this process is adding GRAPHICS to a panel on the main window. How to I trigger the paint event on the window from this method? Is it possible that this method is not allowing events to be processed by the window/form?
|
|
|
|
|
nrbracke wrote: Is it possible that this method is not allowing events to be processed by the window/form?
Yes it's possible.
You can, however, force the window to get an immediate WM_PAINT message by invalidating part
or all of the window (see InvalidateRect()/InvaliateRgn()) and calling UpdateWindow().
Also, check out RedrawWindow(), which combines the above mentioned operations.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If I Invalidate() the windows goes blank untill the method finishes its processing instead of updating with the components I have already added. What is preventing the paint method from getting called?
|
|
|
|
|
You need to call UpdateWindow() as well, so a WM_PAINT message gets sent to
the window. That window would need to actually draw in response to WM_PAINT.
You really should be doing lengthy operations on a separate thread if you want your
UI to stay responsive. By not letting the message loop run, you're preventing the UI
from getting and dispatching the messages it needs.
You could also periodically pump queued messages during your lengthy operation,
something like this:
<span style="color: Green;">
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp()-> PumpMessage())
{
break;
}
}
<span style="color: Green;">
MSG msg;
while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
is there a way to add a popup menu to ClistBox control?
thanks
|
|
|
|
|
Gofur Halmurat wrote: s there a way to add a popup menu to ClistBox control?
One way would be derive a class from CListBox and add a WM_CONTEXTMENU handler
to the class. In that handler, use TrackPopupMenu() to show a popup menu.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I created a class which derived from CListBox, and I added WM_CONTEXTMENU handler, there is a problem, how can i use TrackPopupMenu()in the class?
I have the menus ID = IDR_MENU1, can i call it in the class? if so, how?
thanks
|
|
|
|
|
Gofur Halmurat wrote: I have the menus ID = IDR_MENU1, can i call it in the class? if so, how?
What did you try??
Take a look at TrackPopupMenu() in the PSDK or MSDN.
Here's one example:
CMenu popupmenu;
popupmenu.LoadMenu(IDR_MENU1);
...do some menu initialization if necessary...
int Command = (int)popupmenu.GetSubMenu(0)->TrackPopupMenu(TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, point.x, point.y, this);
...process the command... You can also use an appropriate window and catch the command message the normal MFC way.
You'd have to remove the TPM_RETURNCMD and TPM_NONOTIFY flags.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|