Skip to content

Commit

Permalink
Merge pull request #587 from somdoron/master
Browse files Browse the repository at this point in the history
Fix NetMQ not working Linux with dotnet core
  • Loading branch information
drewnoakes authored Jul 18, 2016
2 parents 12d6d00 + d8a3221 commit b9d6740
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#language: csharp

# dotnet cli require Ubuntu 14.04
sudo: required
dist: trusty

# dotnet cli require OSX 10.10
#osx_image: xcode7.1

addons:
apt:
packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8
- zlib1g

os:
# - osx
- linux

env:
- CLI_VERSION=latest

before_install:
# Install OpenSSL
- if test "$TRAVIS_OS_NAME" == "osx"; then
brew update;
brew install openssl;
brew link --force openssl;
fi

install:

# Download script to install dotnet cli
- curl -L --create-dirs https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh -o ./scripts/install.sh

- export DOTNET_INSTALL_DIR="$PWD/.dotnetcli"

# Install the latest versio of dotnet CLI
- bash ./scripts/install.sh --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR" --no-path

# Add dotnet to PATH
- export PATH="$DOTNET_INSTALL_DIR:$PATH"

script:
- dotnet restore src/

# testing only netcoreapp1.0 on linux and osx
- dotnet test src/NetMQ.Tests -f netcoreapp1.0
2 changes: 2 additions & 0 deletions src/NetMQ-Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
..\.gitattributes = ..\.gitattributes
..\.gitignore = ..\.gitignore
..\.travis.yml = ..\.travis.yml
..\COPYING.LESSER = ..\COPYING.LESSER
global.json = global.json
..\mkdocs.yml = ..\mkdocs.yml
..\README.md = ..\README.md
..\travis.yml = ..\travis.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{FF13931E-D7A0-489E-9530-0F972DAE1167}"
Expand Down
45 changes: 19 additions & 26 deletions src/NetMQ/Core/Transports/Tcp/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU Lesser General Public License
using System;
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using AsyncIO;
using JetBrains.Annotations;

Expand Down Expand Up @@ -49,7 +50,7 @@ internal class TcpListener : Own, IProactorEvents
/// <summary>
/// socket being accepted
/// </summary>
private AsyncSocket m_acceptedSocket;
//private AsyncSocket m_acceptedSocket;

/// <summary>
/// Socket the listener belongs to.
Expand Down Expand Up @@ -136,7 +137,13 @@ public virtual void SetAddress([NotNull] string addr)
}
}

#if NETSTANDARD1_3
// This command is failing on linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
m_handle.ExclusiveAddressUse = false;
#else
m_handle.ExclusiveAddressUse = false;
#endif
m_handle.Bind(m_address.Address);
m_handle.Listen(m_options.Backlog);

Expand All @@ -157,10 +164,10 @@ public virtual void SetAddress([NotNull] string addr)

private void Accept()
{
m_acceptedSocket = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
//m_acceptedSocket = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// start accepting socket async
m_handle.Accept(m_acceptedSocket);
m_handle.Accept();

// Disable TIME_WAIT tcp state
if (m_options.DisableTimeWait)
Expand All @@ -180,12 +187,13 @@ public void InCompleted(SocketError socketError, int bytesTransferred)
case SocketError.Success:
{
// TODO: check TcpFilters
var acceptedSocket = m_handle.GetAcceptedSocket();

m_acceptedSocket.NoDelay = true;
acceptedSocket.NoDelay = true;

if (m_options.TcpKeepalive != -1)
{
m_acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive);
acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive);

if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1)
{
Expand All @@ -197,12 +205,12 @@ public void InCompleted(SocketError socketError, int bytesTransferred)
bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4);
bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8);

m_acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null);
acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null);
}
}

// Create the engine object for this connection.
var engine = new StreamEngine(m_acceptedSocket, m_options, m_endpoint);
var engine = new StreamEngine(acceptedSocket, m_options, m_endpoint);

// Choose I/O thread to run connector in. Given that we are already
// running in an I/O thread, there must be at least one available.
Expand All @@ -216,25 +224,22 @@ public void InCompleted(SocketError socketError, int bytesTransferred)

SendAttach(session, engine, false);

m_socket.EventAccepted(m_endpoint, m_acceptedSocket);
m_socket.EventAccepted(m_endpoint, acceptedSocket);

Accept();
break;
}
case SocketError.ConnectionReset:
case SocketError.NoBufferSpaceAvailable:
case SocketError.TooManyOpenSockets:
{
m_acceptedSocket.Dispose();
{
m_socket.EventAcceptFailed(m_endpoint, socketError.ToErrorCode());

Accept();
break;
}
default:
{
m_acceptedSocket.Dispose();

{
NetMQException exception = NetMQException.Create(socketError);

m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode);
Expand All @@ -260,19 +265,7 @@ private void Close()
{
m_socket.EventCloseFailed(m_endpoint, ex.SocketErrorCode.ToErrorCode());
}

if (m_acceptedSocket != null)
{
try
{
m_acceptedSocket.Dispose();
}
catch (SocketException)
{
}
}

m_acceptedSocket = null;

m_handle = null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"keyFile": "./NetMQ.snk"
},
"dependencies": {
"AsyncIO": "0.1.23",
"AsyncIO": "0.1.26",
"JetBrains.Annotations": {
"version": "10.1.5",
"type": "build"
Expand Down

0 comments on commit b9d6740

Please sign in to comment.