Inheritance: IDisposable
示例#1
0
 protected static void UnregisterSocket(DcmSocket socket)
 {
     lock (_sockets) {
         _sockets.Remove(socket);
         _connections = _sockets.Count;
     }
 }
示例#2
0
		protected static void RegisterSocket(DcmSocket socket) {
			lock (_sockets) {
				if (!_sockets.Contains(socket)) {
					_sockets.Add(socket);
				}
				_connections = _sockets.Count;
			}
		}
示例#3
0
 protected static void RegisterSocket(DcmSocket socket)
 {
     lock (_sockets) {
         if (!_sockets.Contains(socket))
         {
             _sockets.Add(socket);
         }
         _connections = _sockets.Count;
     }
 }
示例#4
0
		protected static void UnregisterSocket(DcmSocket socket) {
			lock (_sockets) {
				_sockets.Remove(socket);
				_connections = _sockets.Count;
			}
		}
示例#5
0
        protected void InitializeNetwork(DcmSocket socket)
        {
            _socket = socket;
            _socket.SendTimeout = _socketTimeout * 1000;
            _socket.ReceiveTimeout = _socketTimeout * 1000;
            _socket.ThrottleSpeed = _throttle;

            OnInitializeNetwork();

            _network = _socket.GetStream();
            _stop = false;
            _isRunning = true;
            _thread = new Thread(Process);
            _thread.IsBackground = true;
            _thread.Start();
        }
示例#6
0
 private void Process()
 {
     try {
         OnConnected();
         _disableTimeout = false;
         DateTime timeout = DateTime.Now.AddSeconds(DimseTimeout);
         while (!_stop) {
             if (_socket.Poll(1000000, SelectMode.SelectRead)) {
                 if (_socket.Available == 0)
                     break;
                 ProcessNextPDU();
                 timeout = DateTime.Now.AddSeconds(DimseTimeout);
             }
             else if (_disableTimeout) {
                 timeout = DateTime.Now.AddSeconds(DimseTimeout);
             }
             else if (DimseTimeout != 0 && DateTime.Now > timeout) {
                 Log.Error("{0} -> DIMSE timeout after {1} seconds", LogID, DimseTimeout);
                 OnDimseTimeout();
                 _stop = true;
             }
             else if (!_socket.Connected)
                 break;
         }
         Log.Info("{0} -> Connection closed", LogID);
         OnConnectionClosed();
     }
     catch (SocketException e) {
         if (e.SocketErrorCode == SocketError.TimedOut)
             Log.Error("{0} -> Network timeout after {1} seconds", LogID, SocketTimeout);
         else
             Log.Error("{0} -> Network error: {1}", LogID, e.Message);
         OnNetworkError(e);
         OnConnectionClosed();
     }
     catch (Exception e) {
     #if DEBUG
         Log.Error("{0} -> Processing failure: {1}", LogID, e.ToString());
     #else
         Log.Error("{0} -> Processing failure: {1}", LogID, e.Message);
     #endif
         OnNetworkError(e);
         Log.Info("{0} -> Connection closed", LogID);
         OnConnectionClosed();
     }
     finally {
         try { _network.Close(); } catch { }
         _network = null;
         try { _socket.Close(); } catch { }
         _socket = null;
         _isRunning = false;
         _dimse = null;
     }
 }
示例#7
0
        private void Connect()
        {
            bool success = false;

            try {
                Log.Info("{0} -> Connecting to server at {1}:{2}", LogID, _host, _port);

                _socket = DcmSocket.Create(_socketType);
                _socket.ConnectTimeout = _connectTimeout * 1000;
                _socket.SendTimeout = _socketTimeout * 1000;
                _socket.ReceiveTimeout = _socketTimeout * 1000;
                _socket.ThrottleSpeed = _throttle;
                _socket.Connect(_host, _port);

                if (_socketType == DcmSocketType.TLS)
                    Log.Info("{0} -> Authenticating SSL/TLS for server: {1}", LogID, _socket.RemoteEndPoint);

                OnInitializeNetwork();

                _network = _socket.GetStream();
                success = true;
            }
            catch (SocketException e) {
                if (e.SocketErrorCode == SocketError.TimedOut)
                    Log.Error("{0} -> Connection timeout after {1} seconds", LogID, _connectTimeout);
                else
                    Log.Error("{0} -> Network error: {1}", LogID, e.Message);
                OnNetworkError(e);
                OnConnectionClosed();
            }
            catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Processing failure: {1}", LogID, e.ToString());
            #else
                Log.Error("{0} -> Processing failure: {1}", LogID, e.Message);
            #endif
                OnNetworkError(e);
                OnConnectionClosed();
            }
            finally {
                if (!success) {
                    if (_network != null) {
                        try { _network.Close(); }
                        catch { }
                        _network = null;
                    }
                    if (_socket != null) {
                        try { _socket.Close(); }
                        catch { }
                        _socket = null;
                    }
                    _isRunning = false;
                }
            }

            if (success)
                Process();
        }
示例#8
0
 public NetworkErrorStream(DcmSocket socket)
 {
     _socket = new WeakReference(socket);
     InternalSocket.Hook(this);
 }
		public NetworkErrorStream(DcmSocket socket) {
			_socket = new WeakReference(socket);
			InternalSocket.Hook(this);
		}