Click here to Skip to main content
15,895,084 members
Articles / Desktop Programming / Win32

SSL : Convert your Plain Sockets to SSL Sockets in an Easy Way

Rate me:
Please Sign up or sign in to vote.
4.83/5 (21 votes)
14 Mar 2008CPOL3 min read 248.4K   7K   55  
A simple class that allows you to convert an existing SOCKET handle to SSL under Windows
#ifndef _Z_H
#define _Z_H

// Z template class
template <class T>class Z
	{
   private:

   	T* d;
      unsigned int ss;

   public:

   	Z(int s = 0)
			{
			if (!s)
				s = 1;
			d = new T[s];
			memset(d,0,s*sizeof(T));
			ss = s;
			}
		~Z()
			{
	      delete[] d;
			}

      operator T*()
			{
			return d;
			}

	void _clear()
		{
		ZeroMemory(d,ss*sizeof(T));
		}
	void clear()
		{
		ZeroMemory(d,ss*sizeof(T));
		}

	int bs()
		{
		return ss*sizeof(T);
		}

	int is()
		{
		return ss;
		}

	void Resize(unsigned int news)
		{
		if (news == ss)
			return; // same size

		// Create buffer to store existing data
		T* newd = new T[news];
		int newbs = news*sizeof(T);
		ZeroMemory((void*)newd, newbs);

		if (ss < news)
			// we created a larger data structure
			memcpy((void*)newd,d,ss*sizeof(T));
		else
			// we created a smaller data structure
			memcpy((void*)newd,d,news*sizeof(T));
		delete[] d;
		d = newd;
		ss = news;
		}

	void AddResize(int More)
		{
		Resize(ss + More);
		}

   };

#endif

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Greece Greece
I'm working in C++, PHP , Java, Windows, iOS, Android and Web (HTML/Javascript/CSS).

I 've a PhD in Digital Signal Processing and Artificial Intelligence and I specialize in Pro Audio and AI applications.

My home page: https://www.turbo-play.com

Comments and Discussions