CSock - To verify timeout socket class

Environment: VC6, WindosNT4 SP3


I'm korean and not good at English.

In case of using CSocket class, We have problem to verify connction between computers.
This class(CSock) is solving this problem with method below.
CSocket don't return the proper time when it disconnects another socket.
This cause performance of program to down.

I can find method to solve this problem. I make the class 'CSock'.

If input time-value exceed the time limit,
my Overrided function immediatily return the response.

CSock class is overriding ConnectHelper of CSocket class member functions



/// CSocket modify - timeout module.
BOOL CSock::ConnectHelper(const SOCKADDR* lpSockAddr, int nSockAddrLen)
{
	if (m_pbBlocking != NULL)
	{
		WSASetLastError(WSAEINPROGRESS);
		return  FALSE;
	}

	m_nConnectError = -1;

	if (!CAsyncSocket::ConnectHelper(lpSockAddr, nSockAddrLen))
	{
		if (GetLastError() == WSAEWOULDBLOCK)
		{
	// Insert....
			CTime		curt, st;
			CTimeSpan	span(0, 0, 0, m_nTimeOut);

			st = CTime().GetCurrentTime();
	//.......
			while (PumpMessages(FD_CONNECT))
			{
				if (m_nConnectError != -1)
				{
					WSASetLastError(m_nConnectError);
					return (m_nConnectError == 0);
				}
	// Insert....
				curt = CTime().GetCurrentTime();
				if(curt > (st+span))
					return FALSE;
	//..............
			}
		}
		return FALSE;
	}
	m_Kill = FALSE;
	return TRUE;
}


Download demo & source project - 35 Kb



Comments

  • Good!!

    Posted by Legacy on 11/03/2003 12:00am

    Originally posted by: Iampro

    thanks very much!!

    Reply
  • Thanks!!! Very Good!!

    Posted by Legacy on 09/24/2002 12:00am

    Originally posted by: Kwack ManYoung

    I can't understand it

    But I Use it..^.^

    I Pride of you are Korean...

    Reply
  • it looks like the timeout of the base class is in minutes.

    Posted by Legacy on 05/08/2002 12:00am

    Originally posted by: njkayaker

    It looks like the timeout of the base class is in minutes. The derived class makes the timeout in seconds.

    Reply
  • Suggest

    Posted by Legacy on 11/08/2001 12:00am

    Originally posted by: Jiacy

    The m_nTimeOut is used in the class CSocket's member function PumpMessage()(you can see MFC's source file Sockcore.cpp),and I think the parameter can't be used by this way.We can define a new parameter in the class CSock replacing the m_nTimeOut.I also want to knew the use of the function ConnectHelper(). Anyway your method is very smart.Thanks!

    Reply
  • very usefull! thx

    Posted by Legacy on 11/07/2000 12:00am

    Originally posted by: chshin77

    ^_^; 
    

    Reply
  • One Question about recv() function

    Posted by Legacy on 11/16/1999 12:00am

    Originally posted by: syhwang

    Hi~

    I'm a person in KOREA.

    I met one problem for programming about socket

    I used CSocket class and member function.

    The problem is that...

    I send several packet with send() function...

    and I received with recv() function in other socket app.

    when the recv function finished,

    the received packet have several send packet
    that is, One recv() call gets several send packet...

    I want to received only one send packet...

    How can I do it...?

    Please help me~~

    Thank you

    Reply
  • But how does your demo function?

    Posted by Legacy on 07/28/1999 12:00am

    Originally posted by: zhutong

    I setup your demo program, and connect to a host,
    
    then close the host, nothing happened....

    Pls tell me how to use it

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds