SetDaemon() 공개 메소드

public SetDaemon ( bool daemon ) : void
daemon bool
리턴 void
예제 #1
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void EnsureOpen(int timeout)
        {
            _closeTimeout = 0;
            if (SoTimeout != 0)
            {
                _closeTimeout = Math.Max(SoTimeout, timeout);
            }
            // If socket is still good, the new closeTimeout will
            // be ignored; see tryClose comment.
            if (_socket == null)
            {
                _socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                //IPAddress.`Address` property deleted
                //_socket.Bind(new IPEndPoint(laddr.Address, _lport));
                _socket.Bind(new IPEndPoint(laddr, _lport));

                if (_waitResponse)
                {
                    _thread = new Thread(this); //new Sharpen.Thread(this, "JCIFS-NameServiceClient");
                    _thread.SetDaemon(true);
                    _thread.Start();
                }
            }
        }
예제 #2
0
        public Thread NewThread(IRunnable r)
        {
            Thread t = new Thread(r);

            t.SetDaemon(true);
            t.Start(true);

            return(t);
        }
예제 #3
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void EnsureOpen(int timeout)
        {
            //Log.Out($"NameServiceClient.EnsureOpen");

            _closeTimeout = 0;
            if (SoTimeout != 0)
            {
                _closeTimeout = Math.Max(SoTimeout, timeout);
            }

            var localPort = (SmbConstants.Lport == 0) ? _lport : SmbConstants.Lport;

            // If socket is still good, the new closeTimeout will
            // be ignored; see tryClose comment.
            if (
                _socketSender == null ||
                _socketSender.LocalEndPoint == null ||
                _socketSender.GetLocalPort() != localPort ||
                !IPAddress.Any.Equals(_socketSender.GetLocalInetAddress())
                )
            {
                if (_socketSender != null)
                {
                    _socketSender.Dispose();
                    _socketSender = null;
                }

                _socketSender = new SocketEx(AddressFamily.InterNetwork,
                                             SocketType.Dgram,
                                             ProtocolType.Udp);

                _socketSender.Bind(new IPEndPoint(IPAddress.Any, localPort));


                if (_waitResponse)
                {
                    if (_thread != null)
                    {
                        _thread.Cancel(true);
                        _thread.Dispose();
                    }

                    _thread = new Thread(this);
                    _thread.SetDaemon(true);
                    _thread.Start(true);
                }
            }
        }
예제 #4
0
        internal virtual NbtAddress[] GetHosts()
        {
            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    NodeStatusRequest request;
                    NodeStatusResponse response;

                    byte[] addrBytes = {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                        addr.GetAddress(), false, 0x20));
                    request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked(0x20), null));
                    request.Addr = addr;
                    Send(request, response, 0);
                }

            }
            catch (IOException ioe)
            {
                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);
            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start();

            _autoResetWaitReceive.WaitOne();

            List<NbtAddress> result = new List<NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                NodeStatusResponse resp = (NodeStatusResponse)_responseTable[key];

                if (resp.Received && resp.ResultCode == 0)
                {
                    foreach (var entry in resp.AddressArray)
                    {
                        if (entry.HostName.HexCode == 0x20)
                        {
                            result.Add(entry);
                        }
                    }
                }
            }

            _responseTable.Clear();

            _waitResponse = true;

            return result.Count > 0 ? result.ToArray() : null;
        }
예제 #5
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void EnsureOpen(int timeout)
        {
            _closeTimeout = 0;
            if (SoTimeout != 0)
            {
                _closeTimeout = Math.Max(SoTimeout, timeout);
            }
            // If socket is still good, the new closeTimeout will
            // be ignored; see tryClose comment.
            if (_socket == null)
            {
                _socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _socket.Bind(new IPEndPoint(laddr, _lport));

                if (_waitResponse)
                {
                    _thread = new Thread(this); //new Sharpen.Thread(this, "JCIFS-NameServiceClient");
                    _thread.SetDaemon(true);
                    _thread.Start();
                }
            }
        }
예제 #6
0
        internal virtual NbtAddress[] GetHosts()
        {
            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    NodeStatusRequest  request;
                    NodeStatusResponse response;

                    byte[] addrBytes =
                    {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    //response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                    //    (int)addr.Address, false, 0x20));
                    response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                                                                     BitConverter.ToInt32(addr.GetAddressBytes(), 0), false, 0x20));

                    request      = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked (0x20), null));
                    request.Addr = addr;
                    Send(request, response, 0);
                }
            }
            catch (IOException ioe)
            {
                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);
            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start();

            _autoResetWaitReceive.WaitOne();

            List <NbtAddress> result = new List <NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                NodeStatusResponse resp = (NodeStatusResponse)_responseTable[key];

                if (resp.Received && resp.ResultCode == 0)
                {
                    foreach (var entry in resp.AddressArray)
                    {
                        if (entry.HostName.HexCode == 0x20)
                        {
                            result.Add(entry);
                        }
                    }
                }
            }

            _responseTable.Clear();

            _waitResponse = true;

            return(result.Count > 0 ? result.ToArray() : null);
        }
예제 #7
0
        internal virtual NbtAddress[] GetHosts()
        {
            //Log.Out("NbtServiceClient.GetHosts");

            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    //Log.Out($"NbtServiceClient.GetHosts - {i}");

                    NodeStatusRequest  request;
                    NodeStatusResponse response;

                    byte[] addrBytes =
                    {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    response = new NodeStatusResponse(
                        new NbtAddress(NbtAddress.UnknownName,
                                       BitConverter.ToInt32(addr.GetAddressBytes(), 0),
                                       false,
                                       0x20)
                        );

                    request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName,
                                                             unchecked (0x20),
                                                             null))
                    {
                        Addr = addr
                    };

                    Send(request, response, 0);
                }
            }
            catch (IOException ioe)
            {
                //Log.Out(ioe);

                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);

            if (_thread != null)
            {
                _thread.Cancel(true);
                _thread.Dispose();
            }

            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start(true);

            _autoResetWaitReceive.WaitOne();

            var result = new List <NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                var resp = (NodeStatusResponse)_responseTable[key];

                if (!resp.Received || resp.ResultCode != 0)
                {
                    continue;
                }

                result.AddRange(resp.AddressArray
                                .Where(entry => entry.HostName.HexCode == 0x20));
            }

            _responseTable.Clear();

            _waitResponse = true;

            return(result.Count > 0 ? result.ToArray() : null);
        }
예제 #8
0
		/// <exception cref="SharpCifs.Util.Transport.TransportException"></exception>
		public virtual void Connect(long timeout)
		{
			lock (this)
			{
				try
				{
					switch (State)
					{
						case 0:
						{
							break;
						}

						case 3:
						{
							return;
						}

						case 4:
						{
							// already connected
							State = 0;
							throw new TransportException("Connection in error", Te);
						}

						default:
						{
							//TransportException te = new TransportException("Invalid state: " + state);
							State = 0;
                            throw new TransportException("Invalid state: " + State);
						}
					}
					State = 1;
					Te = null;
					Thread = new Thread(this);
					Thread.SetDaemon(true);
					lock (Thread)
					{
						Thread.Start();
						Runtime.Wait(Thread, timeout);
						switch (State)
						{
							case 1:
							{
								State = 0;
								Thread = null;
								throw new TransportException("Connection timeout");
							}

							case 2:
							{
								if (Te != null)
								{
									State = 4;
									Thread = null;
									throw Te;
								}
								State = 3;
								return;
							}
						}
					}
				}
				catch (Exception ie)
				{
					State = 0;
					Thread = null;
					throw new TransportException(ie);
				}
				finally
				{
					if (State != 0 && State != 3 && State != 4)
					{
						if (Log.Level >= 1)
						{
							Log.WriteLine("Invalid state: " + State);
						}
						State = 0;
						Thread = null;
					}
				}
			}
		}