This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A std::shared_ptr uses reference counting, so circular references are potentially a problem. | |
To break up cycles, std::weak_ptr can be used to access the stored object. | |
The stored object will be deleted if the only references to the object are weak_ptr references. | |
weak_ptr therefore does not ensure that the object will continue to exist, but it can ask for the resource. */ | |
std::shared_ptr<int> p1(new int(5)); | |
std::weak_ptr<int> wp1 = p1; //p1 owns the memory. | |
{ | |
std::shared_ptr<int> p2 = wp1.lock(); //Now p1 and p2 own the memory. | |
if(p2) //Always check to see if the memory still exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::unique_ptr<int> p1(new int(5)); | |
std::unique_ptr<int> p2 = p1; //Compile error. | |
std::unique_ptr<int> p3 = std::move(p1); //Transfers ownership. p3 now owns the memory and p1 is rendered invalid. | |
p3.reset(); //Deletes the memory. | |
p1.reset(); //Does nothing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "C.h" | |
std::shared_ptr<CC> CC::CreateCC(int x) | |
{ | |
return std::make_shared<CC>(CC::Key(),x); | |
} | |
CC::CC(const Key& rk, int xy) | |
{ | |
y = xy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMyClient::CMyClient(const char* pIP, unsigned int port) | |
{ | |
m_Socket = INVALID_SOCKET; | |
_snprintf_s(this->m_IP,IP_SIZE,_TRUNCATE,pIP); | |
this->InitSockAddrIn(); | |
} | |
void CMyClient::InitSockAddrIn() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*NOTA: | |
1) tem que se garantir que o windows.h é compilado sempre após o ws2tcpip.h, | |
caso contrário começa a indicar que há referencias duplicadas. | |
2) Quando se trabalha com sockets tem sempre que se inicializar a WinSockDLL -> tag WSAStartup */ | |
#include <Ws2tcpip.h> | |
void ShowInfo(struct addrinfo *res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*NOTA: | |
1) tem que se garantir que o windows.h é compilado sempre após o ws2tcpip.h, | |
caso contrário começa a indicar que há referencias duplicadas. | |
2) Quando se trabalha com sockets tem sempre que se inicializar a WinSockDLL -> tag WSAStartup | |
Send function: | |
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740149%28v=vs.85%29.aspx | |
If no error occurs, send returns the total number of bytes sent, which can be *less* | |
than the number requested to be sent in the len parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*NOTA: | |
1) tem que se garantir que o windows.h é compilado sempre após o ws2tcpip.h, | |
caso contrário começa a indicar que há referencias duplicadas. | |
2) Quando se trabalha com sockets tem sempre que se inicializar a WinSockDLL -> tag WSAStartup */ | |
#include <ws2tcpip.h> | |
#include <windows.h> | |
DWORD WINAPI CMyObjec::Receiver(LPVOID arg) // Receive From Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "StdAfx.h" | |
#include "SocketServer.h" | |
#include <iostream> | |
using namespace std; | |
SocketServer::SocketServer() | |
: m_AccepterSocket(INVALID_SOCKET), | |
m_nPort(0), | |
m_dwAccepterThreadID(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <winsock2.h> | |
#include <iostream> | |
using namespace std; | |
bool InitWinsockDLL() | |
{ | |
WSADATA wsaData; | |
// | |
///* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ |