From 6ddd6042ee14bd53198ef4c176c1d732dd78dc38 Mon Sep 17 00:00:00 2001 From: xX-TheDoctor-Xx Date: Fri, 15 Jul 2016 01:39:33 +0100 Subject: [PATCH] Clean up for new library code --- .gitignore | 276 +----------------------------- README | 2 +- VoidNet/VoidNet/Enums.h | 16 -- VoidNet/VoidNet/Socket.cpp | 189 -------------------- VoidNet/VoidNet/Socket.h | 35 ---- VoidNet/VoidNet/TCPConnection.cpp | 1 - VoidNet/VoidNet/TCPConnection.h | 11 -- VoidNet/VoidNet/TCPServer.cpp | 1 - VoidNet/VoidNet/TCPServer.h | 6 - VoidNet/VoidNet/UDPClient.cpp | 0 VoidNet/VoidNet/UDPClient.h | 1 - VoidNet/VoidNet/UDPServer.cpp | 0 VoidNet/VoidNet/UDPServer.h | 1 - 13 files changed, 2 insertions(+), 537 deletions(-) delete mode 100644 VoidNet/VoidNet/Enums.h delete mode 100644 VoidNet/VoidNet/Socket.cpp delete mode 100644 VoidNet/VoidNet/Socket.h delete mode 100644 VoidNet/VoidNet/TCPConnection.cpp delete mode 100644 VoidNet/VoidNet/TCPConnection.h delete mode 100644 VoidNet/VoidNet/TCPServer.cpp delete mode 100644 VoidNet/VoidNet/TCPServer.h delete mode 100644 VoidNet/VoidNet/UDPClient.cpp delete mode 100644 VoidNet/VoidNet/UDPClient.h delete mode 100644 VoidNet/VoidNet/UDPServer.cpp delete mode 100644 VoidNet/VoidNet/UDPServer.h diff --git a/.gitignore b/.gitignore index f955b20..7ff53c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,276 +1,2 @@ -### VisualStudio ### -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb +*.db *.opendb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -### C++ ### -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/README b/README index 56713f3..da240ad 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ # VoidNet -VoidNet is a networking library built with Windows BSD Sockets for maximum efficiency and readability +VoidNet is a networking library built with Windows Sockets for maximum efficiency and reliability diff --git a/VoidNet/VoidNet/Enums.h b/VoidNet/VoidNet/Enums.h deleted file mode 100644 index 7bd5144..0000000 --- a/VoidNet/VoidNet/Enums.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -namespace VoidNet -{ - enum Protocol - { - VOID_TCP, - VOID_UDP - }; - - enum SocketType - { - VOID_CLIENT, - VOID_SERVER - }; -} \ No newline at end of file diff --git a/VoidNet/VoidNet/Socket.cpp b/VoidNet/VoidNet/Socket.cpp deleted file mode 100644 index d9c1d56..0000000 --- a/VoidNet/VoidNet/Socket.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "Socket.h" -#include "Enums.h" - -VoidNet::Socket::Socket(int socketType, int protocolType) : - socketType(socketType), protocolType(protocolType) -{ -} - -VoidNet::Socket::Socket(std::string ipAddr, unsigned int port, int socketType, int protocolType) : - ipAddr(ipAddr), port(port), socketType(socketType), protocolType(protocolType) -{ -} - -VoidNet::Socket::~Socket() -{ -} - -bool VoidNet::Socket::operator==(Socket &Socket) -{ - //return socket == con.socket; - return false; -} - -bool VoidNet::Socket::operator!=(Socket &Socket) -{ - //return socket != con.socket; - return false; -} - -std::string VoidNet::Socket::getIPAddress() -{ - return ipAddr; -} - -std::string VoidNet::Socket::getPeerAddress() -{ - return ipAddr + ":" + std::to_string(port); -} - -bool VoidNet::Socket::connectToHost() -{ - if (!init(socketType, protocolType)) - return false; - - if (connect(soc, addrInfo->ai_addr, addrInfo->ai_addrlen) != SOCKET_ERROR) - return true; - closesocket(soc); - soc = INVALID_SOCKET; - freeaddrinfo(addrInfo); - WSACleanup(); - return false; -} - -bool VoidNet::Socket::sendBytes(const char *buffer, int length) -{ - if (send(soc, buffer, length, 0) == SOCKET_ERROR) - return false; - return true; -} - -bool VoidNet::Socket::receiveBytes(char *buffer, int length) -{ - if (recv(soc, buffer, length, 0) == 0) - return false; - return true; -} - -bool VoidNet::Socket::shutdownReceive() -{ - if (shutdown(soc, SD_RECEIVE) == SOCKET_ERROR) - return false; - return true; -} - -bool VoidNet::Socket::shutdownSend() -{ - if (shutdown(soc, SD_SEND) == SOCKET_ERROR) - return false; - return true; -} - -bool VoidNet::Socket::dataAvailable(int &size) -{ - if (ioctlsocket(soc, FIONREAD, (u_long*)size) != NO_ERROR && size > 0) - return true; - return false; -} - -bool VoidNet::Socket::dataAvailable() -{ - int s; - return dataAvailable(s); -} - -bool VoidNet::Socket::setBlocking(bool blocking) -{ - if (ioctlsocket(soc, FIONBIO, (u_long*)(blocking ? 1 : 0)) != NO_ERROR) - return true; - return false; -} - -unsigned int VoidNet::Socket::getPortNumber() -{ - return port; -} - -bool VoidNet::Socket::init(int socketType, int protocolType) -{ - if (soc != NULL) - { - try - { - shutdownReceive(); - shutdownSend(); - closesocket(soc); - WSACleanup(); - soc = NULL; - } - catch (std::exception) { } - } - - WSADATA wsaData; - - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) - return false; - - struct addrinfo *result = nullptr, hints; - - if (socketType == VOID_CLIENT && protocolType == VOID_TCP) - { - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - } - else if (socketType == VOID_CLIENT && protocolType == VOID_UDP) - { - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_UDP; - } - else if (socketType == VOID_SERVER && protocolType == VOID_TCP) - { - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; - } - else if (socketType == VOID_SERVER && protocolType == VOID_UDP) - { - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_UDP; - hints.ai_flags = AI_PASSIVE; - } - - if (socketType == VOID_CLIENT) - { - if (getaddrinfo(ipAddr.c_str(), (PCSTR)port, &hints, &result) == SOCKET_ERROR) - { - WSACleanup(); - return false; - } - } - else - { - if (getaddrinfo(nullptr, (PCSTR)port, &hints, &result) == SOCKET_ERROR) - { - WSACleanup(); - return false; - } - } - - auto Socket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - - if (Socket == INVALID_SOCKET) - { - freeaddrinfo(result); - WSACleanup(); - return false; - } - - addrInfo = result; - soc = Socket; - return true; -} diff --git a/VoidNet/VoidNet/Socket.h b/VoidNet/VoidNet/Socket.h deleted file mode 100644 index 7226347..0000000 --- a/VoidNet/VoidNet/Socket.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include - -namespace VoidNet -{ - struct Socket - { - Socket(int, int); - Socket(std::string, unsigned int, int, int); - ~Socket(); - bool operator == (Socket&); - bool operator != (Socket&); - unsigned int getPortNumber(); - std::string getIPAddress(); - std::string getPeerAddress(); - bool connectToHost(); - bool sendBytes(const char*, int); - bool receiveBytes(char*, int); - bool shutdownReceive(); - bool shutdownSend(); - bool dataAvailable(int&); - bool dataAvailable(); - bool setBlocking(bool); - private: - SOCKET soc; - struct addrinfo *addrInfo; - std::string ipAddr; - unsigned int port; - int socketType; - int protocolType; - bool init(int, int); - }; -} \ No newline at end of file diff --git a/VoidNet/VoidNet/TCPConnection.cpp b/VoidNet/VoidNet/TCPConnection.cpp deleted file mode 100644 index e864e81..0000000 --- a/VoidNet/VoidNet/TCPConnection.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "TCPConnection.h" \ No newline at end of file diff --git a/VoidNet/VoidNet/TCPConnection.h b/VoidNet/VoidNet/TCPConnection.h deleted file mode 100644 index 5260c5a..0000000 --- a/VoidNet/VoidNet/TCPConnection.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "Socket.h" - -namespace VoidNet -{ - struct TCPConnection - { - - }; -} \ No newline at end of file diff --git a/VoidNet/VoidNet/TCPServer.cpp b/VoidNet/VoidNet/TCPServer.cpp deleted file mode 100644 index a02832b..0000000 --- a/VoidNet/VoidNet/TCPServer.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "TCPServer.h" \ No newline at end of file diff --git a/VoidNet/VoidNet/TCPServer.h b/VoidNet/VoidNet/TCPServer.h deleted file mode 100644 index cdb10e8..0000000 --- a/VoidNet/VoidNet/TCPServer.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -struct TCPServer -{ - -}; \ No newline at end of file diff --git a/VoidNet/VoidNet/UDPClient.cpp b/VoidNet/VoidNet/UDPClient.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/VoidNet/VoidNet/UDPClient.h b/VoidNet/VoidNet/UDPClient.h deleted file mode 100644 index 6f70f09..0000000 --- a/VoidNet/VoidNet/UDPClient.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/VoidNet/VoidNet/UDPServer.cpp b/VoidNet/VoidNet/UDPServer.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/VoidNet/VoidNet/UDPServer.h b/VoidNet/VoidNet/UDPServer.h deleted file mode 100644 index 6f70f09..0000000 --- a/VoidNet/VoidNet/UDPServer.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once