LosaDev source snapshot 2019

This commit is contained in:
LosaDev committed 2026-11-07 13:30:45 +07:00
commit c198676e97
20588 files changed
+8812878

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LS_CSocket", "LS_CSocket.vcxproj", "{C338F3EA-92D2-4B82-840A-A9F89465B056}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C338F3EA-92D2-4B82-840A-A9F89465B056}.Debug|Win32.ActiveCfg = Debug|Win32
{C338F3EA-92D2-4B82-840A-A9F89465B056}.Debug|Win32.Build.0 = Debug|Win32
{C338F3EA-92D2-4B82-840A-A9F89465B056}.Release|Win32.ActiveCfg = Release|Win32
{C338F3EA-92D2-4B82-840A-A9F89465B056}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+140
View File
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="ks_c_5601-1987"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="LS_CSocket"
ProjectGUID="{C338F3EA-92D2-4B82-840A-A9F89465B056}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="4"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="../lib/LS_CSocketD.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="4"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="../lib/LS_CSocket.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="소스 파일"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\ioCSocket.cpp">
</File>
<File
RelativePath=".\ioCSocketTCP.cpp">
</File>
<File
RelativePath=".\ioCSocketUDP.cpp">
</File>
<File
RelativePath=".\StdAfx.cpp">
</File>
</Filter>
<Filter
Name="헤더 파일"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\include\ioCSocket.h">
</File>
<File
RelativePath="..\include\ioCSocketTCP.h">
</File>
<File
RelativePath="..\include\ioCSocketUDP.h">
</File>
</Filter>
<Filter
Name="리소스 파일"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+21
View File
@@ -0,0 +1,21 @@
========================================================================
정적 라이브러리 : LS_CSocket 프로젝트 개요
========================================================================
응용 프로그램 마법사에서 이 LS_CSocket 라이브러리 프로젝트를 만들었습니다.
프로젝트에 대해 소스 파일은 만들어지지 않았습니다.
LS_CSocket.vcproj
응용 프로그램 마법사를 사용하여 생성한 VC++ 프로젝트의 기본 프로젝트 파일입니다.
해당 파일을 생성한 Visual C++의 버전 정보를 비롯하여
응용 프로그램 마법사에서 선택한 플랫폼, 구성 및
프로젝트 기능에 대한 정보가 들어 있습니다.
/////////////////////////////////////////////////////////////////////////////
기타 참고:
응용 프로그램 마법사에서 사용하는 "TODO:" 주석은 사용자가 추가하거나 사용자 지정해야 하는
소스 코드 부분을 나타냅니다.
/////////////////////////////////////////////////////////////////////////////
+8
View File
@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TClientSocket.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
+30
View File
@@ -0,0 +1,30 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__4B60893C_5587_4218_831F_77DC84E78660__INCLUDED_)
#define AFX_STDAFX_H__4B60893C_5587_4218_831F_77DC84E78660__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#include <winsock2.h>
#include <process.h>
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__4B60893C_5587_4218_831F_77DC84E78660__INCLUDED_)
+80
View File
@@ -0,0 +1,80 @@
#include "StdAfx.h"
#include <stdio.h>
#include "ioCSocket.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ioCSocket::ioCSocket(void) : m_socket(INVALID_SOCKET), m_connected(FALSE), m_error(0), m_threadId(0)
{
Init();
}
ioCSocket::~ioCSocket(void)
{
Destroy();
}
void ioCSocket::Init()
{
ZeroMemory(&m_sockAddr, sizeof(m_sockAddr));
}
void ioCSocket::Destroy()
{
}
//////////////////////////////////////////////////////////////////////
// Operations
//////////////////////////////////////////////////////////////////////
BOOL ioCSocket::Startup()
{
WSADATA wsaData;
WORD version = MAKEWORD( 2, 2 );
if( WSAStartup( version, &wsaData ) == SOCKET_ERROR )
{
return FALSE;
}
return TRUE;
}
void ioCSocket::Cleanup()
{
WSACleanup();
}
void ioCSocket::Debug(const TCHAR *format, ...)
{
TCHAR buffer[2048];
va_list marker;
va_start( marker, format );
_vsnprintf( buffer, sizeof(buffer), format, marker );
va_end( marker );
#ifdef _DEBUG
OutputDebugString( buffer );
#endif
}
void ioCSocket::Error()
{
LPVOID buffer = NULL;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
reinterpret_cast<LPTSTR>(&buffer),
0,
NULL );
Debug( "ERROR MESSAGE : %s\n", buffer );
LocalFree( buffer );
}
+246
View File
@@ -0,0 +1,246 @@
// TCPSockClient.cpp: implementation of the ioCSocketTCP class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ioCSocketTCP.h"
UINT WINAPI TCPSocketThread( LPVOID handle );
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ioCSocketTCP::ioCSocketTCP()
{
Init();
m_bState = true;
}
ioCSocketTCP::~ioCSocketTCP()
{
Destroy();
}
void ioCSocketTCP::Init()
{
}
void ioCSocketTCP::Destroy()
{
Disconnect();
}
//////////////////////////////////////////////////////////////////////
// Operations
//////////////////////////////////////////////////////////////////////
BOOL ioCSocketTCP::Create()
{
m_socket = ::socket(AF_INET, SOCK_STREAM, 0);
if(m_socket == INVALID_SOCKET)
{
return FALSE;
}
return TRUE;
}
BOOL ioCSocketTCP::Connect(const char *IP, int port)
{
Disconnect();
Create();
m_bState = true;
m_sockAddr.sin_family = AF_INET;
m_sockAddr.sin_port = htons( port );
m_sockAddr.sin_addr.s_addr = inet_addr( IP );
int result = ::connect( m_socket,
reinterpret_cast<SOCKADDR*>(&m_sockAddr),
sizeof(m_sockAddr));
if(SOCKET_ERROR == result)
{
if(WSAGetLastError() != WSAEWOULDBLOCK)
{
return FALSE;
}
}
if(FALSE == SetOptions())
{
return FALSE;
}
m_connected = TRUE;
OnConnect();
CreateThread();
return TRUE;
}
void ioCSocketTCP::Disconnect()
{
if(m_socket != INVALID_SOCKET)
{
//::shutdown(m_socket, SD_BOTH); TIME_WAIT이 발생함, SO_LINGER 옵션을 무효화 시키는 듯함
::closesocket(m_socket);
m_socket = INVALID_SOCKET;
m_connected = FALSE;
OnDisconnect();
}
if(0 != m_threadId)
{
// _endthreadex(m_threadId); // 여기서 행걸림
m_bState = false;
m_threadId = 0;
}
}
BOOL ioCSocketTCP::SetOptions()
{
if(m_socket != INVALID_SOCKET)
{
// socket reuse
{
BOOL reuse = TRUE;
::setsockopt(
m_socket,
SOL_SOCKET,
SO_REUSEADDR,
reinterpret_cast<char*>(&reuse),
sizeof(reuse));
}
// TCP nodelay
{
BOOL nodelay = TRUE;
::setsockopt(
m_socket,
IPPROTO_TCP,
TCP_NODELAY,
reinterpret_cast<char*>(&nodelay),
sizeof(nodelay) );
}
// linger option
{
LINGER ln;
ln.l_onoff = 1;
ln.l_linger = 0;
::setsockopt(
m_socket,
SOL_SOCKET,
SO_LINGER,
reinterpret_cast<char*>(&ln),
sizeof(ln));
}
}
return TRUE;
}
BOOL ioCSocketTCP::Send(const char *buffer, int length)
{
int totalBytes = 0;
while(totalBytes < length)
{
int sentBytes = ::send( m_socket,
buffer + totalBytes,
length - totalBytes,
0 );
if(SOCKET_ERROR == sentBytes)
{
m_error = WSAGetLastError();
Disconnect();
return FALSE;
}
totalBytes += sentBytes;
}
OnSend();
return TRUE;
}
BOOL ioCSocketTCP::Receive(char *buffer, int& length)
{
int received = ::recv( m_socket,
buffer,
length,
0 );
if(received > 0)
{
length = received;
return TRUE;
}
if(0 == received)
{
length = 0;
m_error = 0;
return FALSE;
}
else
{
length = 0;
m_error = WSAGetLastError();
return FALSE;
}
}
BOOL ioCSocketTCP::CreateThread()
{
if(0 == m_threadId)
{
if( _beginthreadex( NULL,
0,
TCPSocketThread,
this,
0,
&m_threadId ) == 0 )
{
return FALSE;
}
}
return TRUE;
}
void ioCSocketTCP::DestroyThread()
{
m_threadId = 0;
}
UINT WINAPI TCPSocketThread( LPVOID handle )
{
ioCSocketTCP *sockTCP = reinterpret_cast<ioCSocketTCP*>(handle);
if(!sockTCP) return 0;
char buffer[MAX_PACKET_SIZE];
while( sockTCP->m_bState )
{
int length = sizeof(buffer);
BOOL result = sockTCP->Receive(buffer, length);
if(TRUE == result)
{
sockTCP->OnReceive(buffer, length);
}
else
{
sockTCP->Error();
sockTCP->Disconnect();
sockTCP->DestroyThread();
break;
}
}
sockTCP->Disconnect();
return 0;
}
+193
View File
@@ -0,0 +1,193 @@
#include "stdafx.h"
#include "ioCSocketUDP.h"
UINT WINAPI UDPSocketThread( LPVOID pHandle );
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ioCSocketUDP::ioCSocketUDP() : m_peerIP(0), m_peerPort(0), m_port(0)
{
Init();
}
ioCSocketUDP::~ioCSocketUDP()
{
Destroy();
}
void ioCSocketUDP::Init()
{
}
void ioCSocketUDP::Destroy()
{
Disconnect();
}
//////////////////////////////////////////////////////////////////////
// Operations
//////////////////////////////////////////////////////////////////////
BOOL ioCSocketUDP::Create()
{
m_socket = ::socket( AF_INET, SOCK_DGRAM, 0 );
if( m_socket == INVALID_SOCKET )
{
return FALSE;
}
return TRUE;
}
BOOL ioCSocketUDP::Bind()
{
SOCKADDR_IN sockAddr;
ZeroMemory( &sockAddr, sizeof(sockAddr) );
while(TRUE)
{
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons( m_port );
sockAddr.sin_addr.s_addr = htonl( INADDR_ANY );
if( bind(m_socket, (LPSOCKADDR)&sockAddr, sizeof(sockAddr)) != SOCKET_ERROR )
{
break;
}
}
return TRUE;
}
BOOL ioCSocketUDP::Connect(const char *IP, int port)
{
Disconnect();
Create();
Bind();
m_sockAddr.sin_family = AF_INET;
m_sockAddr.sin_port = htons( port );
m_sockAddr.sin_addr.s_addr = inet_addr( IP );
int result = ::connect( m_socket,
reinterpret_cast<SOCKADDR*>(&m_sockAddr),
sizeof(m_sockAddr));
if(SOCKET_ERROR == result)
{
if(WSAGetLastError() != WSAEWOULDBLOCK)
{
return FALSE;
}
}
m_connected = TRUE;
OnConnect();
return TRUE;
}
void ioCSocketUDP::Disconnect()
{
if(m_socket != INVALID_SOCKET)
{
::closesocket(m_socket);
m_socket = INVALID_SOCKET;
m_connected = FALSE;
OnDisconnect();
}
}
BOOL ioCSocketUDP::Send(const char *buffer, int length)
{
::sendto( m_socket,
buffer,
length,
0,
NULL,
NULL );
OnSend();
return TRUE;
}
BOOL ioCSocketUDP::Receive(char *buffer, int& length)
{
SOCKADDR_IN sockAddr;
int lengthOfSockAddr;
int received = ::recvfrom( m_socket,
buffer,
length,
0,
(SOCKADDR*)&sockAddr,
&lengthOfSockAddr );
if(received > 0)
{
length = received;
m_peerIP = sockAddr.sin_addr.S_un.S_addr;
m_peerPort = sockAddr.sin_port;
return TRUE;
}
if(0 == received)
{
length = 0;
m_error = 0;
return FALSE;
}
else
{
length = 0;
m_error = WSAGetLastError();
return FALSE;
}
}
BOOL ioCSocketUDP::CreateThread()
{
if( _beginthreadex( NULL,
0,
UDPSocketThread,
this,
0,
&m_threadId ) == 0 )
{
return FALSE;
}
return TRUE;
}
UINT WINAPI UDPSocketThread( LPVOID handle )
{
ioCSocketUDP *sockUDP = reinterpret_cast<ioCSocketUDP*>(handle);
if(!sockUDP) return 0;
char buffer[MAX_PACKET_SIZE * 2];
while( TRUE )
{
int length = sizeof(buffer);
BOOL result = sockUDP->Receive(buffer, length);
if(TRUE == result)
{
sockUDP->OnReceive(buffer, length);
}
else
{
sockUDP->Error();
length = 0;
sockUDP->OnReceive(NULL, length);
}
}
return 0;
}