Skip to content

Commit

Permalink
started working on x64 version
Browse files Browse the repository at this point in the history
  • Loading branch information
FredyH committed Aug 24, 2019
1 parent 0afba9f commit f16faf1
Show file tree
Hide file tree
Showing 3,904 changed files with 334,885 additions and 96,820 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.ipp": "cpp"
}
}
4 changes: 0 additions & 4 deletions BuildProjects.bat

This file was deleted.

85 changes: 49 additions & 36 deletions BuildProjects.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
function os.winSdkVersion()
local reg_arch = iif( os.is64bit(), "\\Wow6432Node\\", "\\" )
local sdk_version = os.getWindowsRegistry( "HKLM:SOFTWARE" .. reg_arch .."Microsoft\\Microsoft SDKs\\Windows\\v10.0\\ProductVersion" )
if sdk_version ~= nil then return sdk_version end
end

solution "GWSockets"

language "C++"
Expand All @@ -15,53 +21,60 @@ solution "GWSockets"

if os.target() == "macosx" or os.target() == "linux" then

buildoptions{ "-m32 -std=c++11 -fPIC" }
linkoptions{ "-fPIC -static-libstdc++" }
buildoptions { "-std=c++11 -fPIC" }
linkoptions { "-static-libstdc++ -fPIC" }

end

configurations
{
"Release"
}
platforms
{
"x32"
}
configurations { "Release" }
platforms { "x86", "x86_64" }

configuration "Release"
defines { "NDEBUG" }
optimize "On"
floatingpoint "Fast"

if os.target() == "windows" then

defines{ "WIN32" }
defines { "NDEBUG" }
optimize "On"
floatingpoint "Fast"

elseif os.target() == "linux" then
if os.target() == "windows" then
defines{ "WIN32" }
elseif os.target() == "linux" then
defines{ "LINUX" }
end

defines{ "LINUX" }
local platform
if os.target() == "windows" then
platform = "win"
links { "libcrypto", "libssl", "boost_system", "crypt32" }
elseif os.target() == "macosx" then
platform = "osx"
links { "ssl", "boost_system" }
elseif os.target() == "linux" then
platform = "linux"
links { "ssl", "boost_system", "pthread", "dl", "crypto" }
else
error "Unsupported platform."
end



filter "platforms:x86"
architecture "x86"
libdirs { "lib/" .. os.target() }
if os.target() == "windows" then
targetname( "gmsv_gwsockets_" .. platform .. "32")
else
targetname( "gmsv_gwsockets_" .. platform)
end
filter "platforms:x86_64"
architecture "x86_64"
libdirs { "lib64/" .. os.target() }
targetname( "gmsv_gwsockets_" .. platform .. "64")
filter {"system:windows", "action:vs*"}
systemversion((os.winSdkVersion() or "10.0.16299") .. ".0")
toolset "v141"

project "GWSockets"
defines{ "GMMODULE", "BOOST_ALL_NO_LIB" }
files{ "src/**.*" }
kind "SharedLib"
libdirs { "libs/" .. os.target() }
local platform
if os.target() == "windows" then
platform = "win32"
links { "libcrypto", "libssl", "boost_system", "crypt32" }
elseif os.target() == "macosx" then
platform = "osx"
links { "ssl", "boost_system" }
elseif os.target() == "linux" then
platform = "linux"
links { "ssl", "boost_system", "pthread", "dl", "crypto" }
else
error "Unsupported platform."
end
targetname( "gmsv_gwsockets_" .. platform)
targetprefix ("")
targetextension (".dll")
targetdir("out/" .. os.target())
targetdir("out/" .. os.target())
3 changes: 0 additions & 3 deletions BuildProjects.sh

This file was deleted.

57 changes: 35 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# GWSockets

WebSockets for GLua

# Usage
## Usage

Place either `gmsv_gwsockets_win32.dll` (Windows) or `gmsv_gwsockets_linux.dll` (Linux) into your `GarrysMod/lua/bin` folder. On windows you will require the Visual C++ Redistributable 2017, which you can find [here](https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads).

*NOTE:* Even though this module is mainly aimed at servers, it can also be used on clients. Just rename the module to `gmcl_gwsockets_os` and it will work on clientside as well.
Expand All @@ -12,18 +14,20 @@ You will also need to require the module in lua before you will be able to use i
require("gwsockets")
```

# Documentation
## Documentation

### Connecting to a socket server

* First initialize a websocket instance using

*NOTE:* URL's must include the scheme ( Either `ws://` or `wss://` )

`Example: "wss://example.com:9999/api/socketserver"`

```LUA
```LUA
GWSockets.createWebSocket( url, verifyCertificate=true )
```

*NOTE:* If you want your websockets to use SSL but don't have a trusted certificate, you can set the second parameter to false.

* Next add any cookies or headers you would like to send with the initial request (Optional)
Expand Down Expand Up @@ -54,14 +58,17 @@ require("gwsockets")
```

* Lastly open the connection

```LUA
WEBSOCKET:open()
```

* Once the socket has been opened you can send messages using the `write` function

```LUA
WEBSOCKET:write( message )
```

*NOTE:* You can write messages to the socket before the connection has been established and the socket
will wait before sending them until the connection has been established. However, it is best practice
to only start sending in the onConnected() callback.
Expand All @@ -77,67 +84,73 @@ require("gwsockets")
* `closeNow` will immediately terminate the connection and discard all queued messages

* You can cancel any queued outbound messages by calling

```LUA
WEBSOCKET:clearQueue()
```

* You can check if the websocket is connected using

```LUA
WEBSOCKET:isConnected()
```

*NOTE:* You should avoid using this and instead rely on the callbacks.



## Example:

```LUA
require("gwsockets")
local socket = GWSockets.createWebSocket("wss://echo.websocket.org/")

function socket:onMessage(txt)
print("Received: ", txt)
print("Received: ", txt)
end

function socket:onError(txt)
print("Error: ", txt)
print("Error: ", txt)
end

-- We start writing only after being connected here. Technically this is not required as this library
-- just waits until the socket is connected before sending, but it's probably good practice
function socket:onConnected()
print("Connected to echo server")
-- Write Echo once every second, 10 times
timer.Create("SocketWriteTimer", 1, 0, function()
print("Writing: ", "Echo")
socket:write("Echo")
end)
timer.Simple(10, function()
timer.Remove("SocketWriteTimer")
-- Even if some of the messages have not reached the other side yet, this type of close makes sure
-- to only close the socket once all queued messages have been received by the peer.
socket:close()
end)
print("Connected to echo server")
-- Write Echo once every second, 10 times
timer.Create("SocketWriteTimer", 1, 0, function()
print("Writing: ", "Echo")
socket:write("Echo")
end)
timer.Simple(10, function()
timer.Remove("SocketWriteTimer")
-- Even if some of the messages have not reached the other side yet, this type of close makes sure
-- to only close the socket once all queued messages have been received by the peer.
socket:close()
end)
end

function socket:onDisconnected()
print("WebSocket disconnected")
print("WebSocket disconnected")
end

socket:open()
```

# Build
## Build

Requires premake5.
Run BuildProjects.sh or BuildProjects.bat with premake5 being installed.
Then use the appropriate generated solution for your system in the solutions/ folder and build the project.

### Windows

On Windows all you need to do is open the generated visual studio project and build the dll. All libraries and headers are provided already.

### Linux

On linux only essential programs for building C++ programs are required. On Ubuntu 64-bit these are:

```console
sudo apt-get install build-essential gcc-multilib g++-multilib
```

The required static libraries for linux are included in this repository to avoid library/header version mismatching, but feel free to use your OS' libraries instead.

8 changes: 4 additions & 4 deletions include/boost/algorithm/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
namespace boost { namespace algorithm {

template <typename T>
T identity_operation ( std::multiplies<T> ) { return T(1); }
BOOST_CXX14_CONSTEXPR T identity_operation ( std::multiplies<T> ) { return T(1); }

template <typename T>
T identity_operation ( std::plus<T> ) { return T(0); }
BOOST_CXX14_CONSTEXPR T identity_operation ( std::plus<T> ) { return T(0); }


/// \fn power ( T x, Integer n )
Expand All @@ -40,7 +40,7 @@ T identity_operation ( std::plus<T> ) { return T(0); }
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
// Seminumerical Algorithms, Section 4.6.3
template <typename T, typename Integer>
typename boost::enable_if<boost::is_integral<Integer>, T>::type
BOOST_CXX14_CONSTEXPR typename boost::enable_if<boost::is_integral<Integer>, T>::type
power (T x, Integer n) {
T y = 1; // Should be "T y{1};"
if (n == 0) return y;
Expand All @@ -67,7 +67,7 @@ power (T x, Integer n) {
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
// Seminumerical Algorithms, Section 4.6.3
template <typename T, typename Integer, typename Operation>
typename boost::enable_if<boost::is_integral<Integer>, T>::type
BOOST_CXX14_CONSTEXPR typename boost::enable_if<boost::is_integral<Integer>, T>::type
power (T x, Integer n, Operation op) {
T y = identity_operation(op);
if (n == 0) return y;
Expand Down
Loading

0 comments on commit f16faf1

Please sign in to comment.