|
Hi,
We are developing an application in which for comminication to outside module we are using WinSock based sime socket approach. Our requirement is to make sure connection will always be on, so for that reason when ever we are getting disconnected or not able to connect to outside module we keep trying after every 1 minute. Our problem starts here we have observered that on every retry of socket reconnect it is leaking exact 2 windows handles, we have tried so many options but none of them are working. Following is the code that we are using right now,
bool CSocketClass::ConnectToServer(int nLineNo)
{
string strIPAddress;
int nPortNo;
SOCKET* l_ClientSocket;
int ConnectionResult;
if (nLineNo == 1)
{
m_objLine1.m_ClientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
strIPAddress = m_objLine1.m_strIPAddress;
nPortNo = m_objLine1.m_nPortNo;
l_ClientSocket = &(m_objLine1.m_ClientSocket);
}
else
{
m_objLine2.m_ClientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
strIPAddress = m_objLine2.m_strIPAddress;
nPortNo = m_objLine2.m_nPortNo;
l_ClientSocket = &(m_objLine2.m_ClientSocket);
}
if(INVALID_SOCKET == *l_ClientSocket)
{
closesocket(*l_ClientSocket);
return false;
}
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( strIPAddress.c_str() );
clientService.sin_port = htons( nPortNo );
ConnectionResult = connect( *l_ClientSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) ;
if (ConnectionResult == SOCKET_ERROR)
{
if (nLineNo == 1)
{
}
else
{
}
closesocket(*l_ClientSocket);
return false;
}
else
{
}
return true;
}
Can anyone help me? Thanks in advance.
|
|
|
|
|
I don't see any problem with this code. How do you use it?
You don't need to call closesocket() if you know the socket is INVALID_SOCKET, and you can simplify your code a bit by using a pointer to m_objLine1 and m_objLine2 instead of copying all entries needed to local variables.
WhatEverType *pObjLine = (nLineNo == 1) &m_objLine1 : &m_objLine2;
if (INVALID_SOCKET == pObjLine->m_ClientSocket)
...
|
|
|
|
|
Ya those things we have added just to check whether they could help us to reduce handle leaks but it dint help us.
We also use pointer approach also but it dint help us either...
This code is being used in one of the windows service which we use to activate manually..
|
|
|
|
|
How are you determining you have a memory leak? Is the MFC mechanism reporting leaks when you end your debug session?
Are you storing MFC CObject derived classes within STL containers or vice versa? I've on occasion gotten false memory leak reports from MFC when mixing STL and MFC (when container classes are involved).
|
|
|
|
|
Hi it seems you get it wrong. I am not talking about memory leaks, leaks I am talking about handle leaks. If I open task manager and look handle count for my application it used to increased by 2 at every connect trial...
|
|
|
|
|
oops. sorry. my bad.
|
|
|
|
|
how to play file fastforward in directshow
|
|
|
|
|
Is this anything to do with C++ or MFC? If so please clarify what you are trying to do and what errors you receive.
I must get a clever new signature for 2011.
|
|
|
|
|
You can use IMediaSeeking::SetRate Method. Obtain the IMediaSeeking interface from FilterGraphManager. I had tried this once, but the required filter in my graph(probably source filter or parser filter needs to implement this method) didn't implement this method. As it was for video playback, handled the play back rate manually with GetPositions and SetPositions methods of IMediaSeeking. However i think this is the only interface that the FilterGraphManager exposes for fast forward and backward playbacks.
|
|
|
|
|
Hello,
When I call to the fanction RegisterPowerSettingNotification I get a runtime error:
"The procedure entry point could not be located in the dynamic link library USER32.dll."
I tried to replace user32.dll but its didnt help.
My OS is windows xp, the code is:
HPOWERNOTIFY m_hPowerSchemeNotify;
m_hPowerSchemeNotify = RegisterPowerSettingNotification (
NULL, &GUID_POWERSCHEME_PERSONALITY,
DEVICE_NOTIFY_WINDOW_HANDLE );
if ( NULL == m_hPowerSchemeNotify )
ATLTRACE("Failed to register for notification of power scheme changes!\n");
if anyone can guid me how can I solve this problam I would be very grateful for him.
thanks
|
|
|
|
|
What version Windows are you running this on?
|
|
|
|
|
How can I know the version ?
I only know that this is
Windows xp professional.
thanks
|
|
|
|
|
OK, according to MSDN, the minimum Windows version for this function is Vista. That means anything before Vista (like XP) won't have this function.
|
|
|
|
|
Thanks
now its obvious why it didnt work.
|
|
|
|
|
Hi all,
i m Using CFileDialog with filter or text file to browse only *.txt files.
but shortcut files are also visible in open file dialog .
please tell me how can i resolve this.
thanks in advance.
|
|
|
|
|
Can you post the code you're using?
|
|
|
|
|
CString filter=_T("Text Files(*.txt)|*.txt||");
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,filter);
if (fileDlg.DoModal () == IDCANCEL)
{
return;
}
CString file_Path = fileDlg.GetPathName ();
AfxMessageBox(file_Path);
|
|
|
|
|
I just tried this code on a folder that has shortcuts, and the shortcuts were not displayed. Did you mean shortcuts, or folders?
|
|
|
|
|
i mean to shortcuts,
i locate a folder by CFileDialog here text files are present and some shortcut of .docx and .xlsx are also presents to these are displayed.
|
|
|
|
|
That's not what I see when I run your code.
|
|
|
|
|
i don't know why its not display on your pc, but if it display than what do yo do for this?
|
|
|
|
|
Recompile your app. Go to the folder where the exe is. Look at the timestamp. If the timestamp is the current time (minus a few seconds), then run your app (double-click) and see what it does.
|
|
|
|
|
how to play file in file frame rate using directshow
|
|
|
|
|
Hi all,
i m using a multiline editbox,and set the limite of text in this text box is 500 char using the function SetLimitText,
its working fine when i m typing over this so its not type more than 500 cahr even its not paste more than 500 char.
but when i m using SetWindowText it enter more than 500 char in this edit box please tell me how can i validate this.
thanks in advance.
|
|
|
|
|
From MSDN: "Changing the text limit via SetLimitText restricts only the text the user can enter. It has no effect on any text already in the edit control, nor does it affect the length of the text copied to the edit control by the SetWindowText member function in CWnd."
|
|
|
|