zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 746 forks source link

What is the purpose of Thread.Sleep within ZMQ.Poll ? #104

Closed JamesWHurst closed 10 years ago

JamesWHurst commented 11 years ago

In module ZMQ.cs, method Poll(PollItem[], int, int), I'm a bit confused by the purpose of Thread.Sleep here, as it would seem to accomplish nothing other than to delay the method from returning. Below is the code..

    public static int Poll(PollItem[] items, int itemsCount, int timeout)
    {
        if (items == null)
        {
            throw NetMQException.Create(ErrorCode.EFAULT);
        }
        if (itemsCount == 0)
        {
            if (timeout <= 0)
                return 0;
            // What's this?
            Thread.Sleep(timeout);
            return 0;
        }

I'm tinkering with the code trying to see how hard it would be to make it work with the version of .NET provided with Windows Store apps, and Sleep is a not available. The solution generally is to use ThreadPoolTimer, but this wouldn't seem to be needed here. Does anyone know -- is it necessary to have it wait for the timeout period, even if itemsCount is zero?

Btw, does anyone share my disappointment with how much the API is changed or limited compared to regular .NET ? I wonder - how much demand is there for compatibility with Windows Store and Windows Phone 8 ? This is clearly a substantial amount of work.

somdoron commented 11 years ago

Because the client specify timeout but there are no items we will delay the return with the timeout.

it's also the behavior of zeromq.

On Sat, Oct 19, 2013 at 4:33 AM, James Hurst notifications@github.comwrote:

In module ZMQ.cs, method Poll(PollItem[], int, int), I'm a bit confused by the purpose of Thread.Sleep here, as it would seem to accomplish nothing other than to delay the method from returning. Below is the code..

public static int Poll(PollItem[] items, int itemsCount, int timeout)
{
    if (items == null)
    {
        throw NetMQException.Create(ErrorCode.EFAULT);
    }
    if (itemsCount == 0)
    {
        if (timeout <= 0)
            return 0;
        // What's this?
        Thread.Sleep(timeout);
        return 0;
    }

I'm tinkering with the code trying to see how hard it would be to make it work with the version of .NET provided with Windows Store apps, and Sleep is a not available. The solution generally is to use ThreadPoolTimer, but this wouldn't seem to be needed here. Does anyone know -- is it necessary to have it wait for the timeout period, even if itemsCount is zero?

Btw, does anyone share my disappointment with how much the API is changed or limited compared to regular .NET ? I wonder - how much demand is there for compatibility with Windows Store and Windows Phone 8 ? This is clearly a substantial amount of work.

— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/104 .

somdoron commented 11 years ago

Regarding the API, it might be easier to only develop a very simple netmq client without all the features just something that know how to talk ZMTP. I know that Pieter Hintjens worked on something similar for embedded devices in C++...

On Sun, Oct 20, 2013 at 11:07 AM, Doron Somech somdoron@gmail.com wrote:

Because the client specify timeout but there are no items we will delay the return with the timeout.

it's also the behavior of zeromq.

On Sat, Oct 19, 2013 at 4:33 AM, James Hurst notifications@github.comwrote:

In module ZMQ.cs, method Poll(PollItem[], int, int), I'm a bit confused by the purpose of Thread.Sleep here, as it would seem to accomplish nothing other than to delay the method from returning. Below is the code..

public static int Poll(PollItem[] items, int itemsCount, int timeout)
{
    if (items == null)
    {
        throw NetMQException.Create(ErrorCode.EFAULT);
    }
    if (itemsCount == 0)
    {
        if (timeout <= 0)
            return 0;
        // What's this?
        Thread.Sleep(timeout);
        return 0;
    }

I'm tinkering with the code trying to see how hard it would be to make it work with the version of .NET provided with Windows Store apps, and Sleep is a not available. The solution generally is to use ThreadPoolTimer, but this wouldn't seem to be needed here. Does anyone know -- is it necessary to have it wait for the timeout period, even if itemsCount is zero?

Btw, does anyone share my disappointment with how much the API is changed or limited compared to regular .NET ? I wonder - how much demand is there for compatibility with Windows Store and Windows Phone 8 ? This is clearly a substantial amount of work.

— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/104 .

somdoron commented 11 years ago

@JamesWHurst can I close the issue?