Example #1
0
        /// <summary>
        /// Shuts down a specific endpoint of this socket.
        /// </summary>
        /// <param name="endpoint">The endpoint created by Connect or Bind which is being shut down.</param>
        /// <returns>True if the endpoint was shut down, false if the shutdown attempt was interrupted and should be reattempted.</returns>
        /// <exception cref="NNanomsg.NanomsgException">Thrown if the socket is in an invalid state or the endpoint's shutdown attempt was interrupted and should be reattempted.</exception>
        public bool Shutdown(NanomsgEndpoint endpoint)
        {
            const int ValidShutdownResult = 0, MaxShutdownAttemptCount = 5;
            int       attemptCount = 0;

            while (true)
            {
                if (Interop.nn_shutdown(_socket, endpoint.ID) != ValidShutdownResult)
                {
                    int error = Interop.nn_errno();

                    // if we were interrupted by a signal, reattempt is allowed by the native library
                    if (error == NanomsgSymbols.EINTR)
                    {
                        if (attemptCount++ >= MaxShutdownAttemptCount)
                        {
                            return(false);
                        }
                        else
                        {
                            Thread.SpinWait(1);
                            continue;
                        }
                    }

                    throw new NanomsgException("nn_shutdown " + endpoint.ID.ToString(), error);
                }
                return(true);
            }
        }
Example #2
0
 public static int Shutdown(int s, int how)
 {
     return(Interop.nn_shutdown(s, how));
 }