Click here to Skip to main content
15,886,362 members
Articles / High Performance Computing / Parallel Processing

Use of free SocketPro package for creating super client and server applications

Rate me:
Please Sign up or sign in to vote.
4.48/5 (19 votes)
23 Feb 200211 min read 179.5K   6.3K   59  
A set of socket libraries for writing distributed computing applications over the internet
// This is a part of the SocketPro package.
// Copyright (C) 2000-2002 UDAParts 
// All rights reserved.
//
// This source code is only intended as a supplement to the
// SocketPro Classes Reference and related
// electronic documentation provided with the package.
// See these sources for detailed information regarding this
// UDAParts product.

// Please don't disclose any source code of the software to any person or entity,
//
// Please don't decompile, disassemble, or reverse engineer any object code of 
// any portion of the software.
//  
// Copyright (c) 2002 by Yuancai (Charlie) Ye
// yekerui@yahoo.com


#ifndef	___SOCKPRO__UTIL_HEADER_FILE___H___
#define ___SOCKPRO__UTIL_HEADER_FILE___H___

class CAutoLock
{
public:
	CAutoLock(CRITICAL_SECTION *pCriticalSection)
	{
		m_pCriticalSection=pCriticalSection;
		if(m_pCriticalSection)
		{
			::EnterCriticalSection(m_pCriticalSection);
		}
	}
	virtual ~CAutoLock()
	{
		if(m_pCriticalSection)
			::LeaveCriticalSection(m_pCriticalSection);
	}
private:
	CRITICAL_SECTION	*m_pCriticalSection;
};

class CPacking
{
public:
	CPacking()
	{
		m_nLen=0;
		m_pBuffer=NULL;
	}
	
	virtual ~CPacking()
	{
		if(m_pBuffer)
		{
			free(m_pBuffer);
		}
	}
	
	void Empty()
	{
		if(m_pBuffer)
		{
			free(m_pBuffer);
			m_pBuffer=NULL;
		}
		m_nLen=0;
	}
	void Pack(const void* pData, unsigned long nBufferLen)
	{
		m_pBuffer = realloc(m_pBuffer,  m_nLen+nBufferLen);
		memcpy((BYTE*)m_pBuffer+m_nLen, pData, nBufferLen);
		m_nLen += nBufferLen;
	}
	
	void Insert(unsigned long nPos, const void* pData, unsigned long nBufferLen)
	{
		if(!pData || nBufferLen==0)
			return;
		if(nPos>m_nLen)
			nPos=m_nLen;
		void *pBuffer=malloc(nBufferLen+m_nLen);
		if(nPos)
			memcpy(pBuffer, m_pBuffer, nPos);
		memcpy((BYTE*)pBuffer + nPos, pData, nBufferLen);
		memcpy((BYTE*)pBuffer + nPos + nBufferLen, (BYTE*)m_pBuffer + nPos, m_nLen-nPos);
		free(m_pBuffer);
		m_pBuffer = pBuffer;
		m_nLen += nBufferLen;
	}

public:
	unsigned long	m_nLen;
	void			*m_pBuffer;
};

#endif

// This is a part of the SocketPro package.
// Copyright (C) 2000-2002 UDAParts 
// All rights reserved.
//
// This source code is only intended as a supplement to the
// SocketPro Classes Reference and related
// electronic documentation provided with the package.
// See these sources for detailed information regarding this
// UDAParts product.

// Please don't disclose any source code of the software to any person or entity,
//
// Please don't decompile, disassemble, or reverse engineer any object code of 
// any portion of the software.
//  
// Copyright (c) 2002 by Yuancai (Charlie) Ye
// yekerui@yahoo.com

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
Yuancai (Charlie) Ye, an experienced C/C++ software engineer, lives in Atlanta, Georgia. He is an expert at continuous inline request/result batching, real-time stream processing, asynchronous data transferring and parallel computation for the best communication throughput and latency. He has been working at SocketPro (https://github.com/udaparts/socketpro) for more than fifteen years.

Comments and Discussions