Ejemplo n.º 1
0
 /// <summary> Adds a new job to the queue. This will be picked up by the next available
 /// active thread.
 /// </summary>
 public void AddJob(AGIConnectionHandler runnable)
 {
     lock (jobs)
     {
         jobs.Add(runnable);
         Monitor.PulseAll(jobs);
     }
 }
Ejemplo n.º 2
0
		public void Start()
		{
			stopped = false;
			mappingStrategy.Load();
			pool = new Util.ThreadPool("AGIServer", poolSize);
#if LOGGER
			logger.Info("Thread pool started.");
#endif
			try
			{
				IPAddress ipAddress = IPAddress.Parse(address);
				serverSocket = new IO.ServerSocket(port, ipAddress, this.SocketEncoding);
			}
			catch(IOException ex)
			{
#if LOGGER
				logger.Error("Unable start AGI Server: cannot to bind to "+ address + ":" + port + ".", ex);
#endif
				throw ex;
			}
#if LOGGER
			logger.Info("Listening on "+ address + ":" + port + ".");
#endif

			AGIConnectionHandler connectionHandler;
			IO.SocketConnection socket;
			try
			{
				while ((socket = serverSocket.Accept()) != null)
				{
#if LOGGER
					logger.Info("Received connection.");
#endif
					connectionHandler = new AGIConnectionHandler(socket, mappingStrategy);
					pool.AddJob(connectionHandler);
				}
			}
			catch (IOException ex)
			{
				if (!stopped)
				{
#if LOGGER
					logger.Error("IOException while waiting for connections (1).", ex);
#endif
					throw ex;
				}
			}
			finally
			{
				if (serverSocket != null)
				{
					try
					{
						serverSocket.Close();
					}
#if LOGGER
					catch (IOException ex)
					{
						logger.Error("IOException while waiting for connections (2).", ex);
					}
#else
					catch { }
#endif
				}
				serverSocket = null;
				pool.Shutdown();
#if LOGGER
				logger.Info("AGIServer shut down.");
#endif
			}
		}
Ejemplo n.º 3
0
        public void Start()
        {
            stopped = false;
            mappingStrategy.Load();
            pool = new Util.ThreadPool("AGIServer", poolSize);
#if LOGGER
            logger.Info("Thread pool started.");
#endif
            try
            {
                IPAddress ipAddress = IPAddress.Parse(address);
                serverSocket = new IO.ServerSocket(port, ipAddress, this.SocketEncoding);
            }
            catch (IOException ex)
            {
#if LOGGER
                logger.Error("Unable start AGI Server: cannot to bind to " + address + ":" + port + ".", ex);
#endif
                throw ex;
            }
#if LOGGER
            logger.Info("Listening on " + address + ":" + port + ".");
#endif

            AGIConnectionHandler connectionHandler;
            IO.SocketConnection  socket;
            try
            {
                while ((socket = serverSocket.Accept()) != null)
                {
#if LOGGER
                    logger.Info("Received connection.");
#endif
                    connectionHandler = new AGIConnectionHandler(socket, mappingStrategy);
                    pool.AddJob(connectionHandler);
                }
            }
            catch (IOException ex)
            {
                if (!stopped)
                {
#if LOGGER
                    logger.Error("IOException while waiting for connections (1).", ex);
#endif
                    throw ex;
                }
            }
            finally
            {
                if (serverSocket != null)
                {
                    try
                    {
                        serverSocket.Close();
                    }
#if LOGGER
                    catch (IOException ex)
                    {
                        logger.Error("IOException while waiting for connections (2).", ex);
                    }
#else
                    catch { }
#endif
                }
                serverSocket = null;
                pool.Shutdown();
#if LOGGER
                logger.Info("AGIServer shut down.");
#endif
            }
        }