Exemplo n.º 1
0
        // read more about this methods and ConcurentQueue
        public IORequestBlock DequeueRequest(out bool isSuccessful)
        {
            IORequestBlock req;

            isSuccessful = IORequests.TryDequeue(out req);
            return(req);
        }
Exemplo n.º 2
0
        public IORequestBlock DequeueRequest(out bool isSuccessful, TimeSpan?timeout = null)
        {
            if (timeout == null)
            {
                timeout = TimeSpan.FromMilliseconds(0);
            }

            TimeSpan       tryTakeTimeout = (TimeSpan)timeout;
            IORequestBlock req;

            isSuccessful = IORequests.TryTake(out req, tryTakeTimeout);
            return(req);
        }
Exemplo n.º 3
0
        public override bool ProcessRequest(IORequestBlock forProcess)
        {
            bool retVal = false;

            if (TrHandler != TransportHandler.TCP)
            {
                Console.WriteLine("ne sme da se desi xD ");
                // to do: throw exception?
                return(false);
            }


            if (tcpClient != null)
            {
                try
                {
                    // to do: test this case...connection lasts forever?
                    if (!tcpClient.Connected)
                    {
                        // to do...sredjivati ovo nekad
                    }

                    NetworkStream stream = tcpClient.GetStream();
                    int           offset = 0;

                    stream.Write(forProcess.SendBuff, offset, forProcess.SendMsgLength);

                    // to do: processing big messages.  whole, or in parts?
                    // ...
                    // ovde dodati taski koji receieve radi

                    forProcess.RcvBuff = new byte[tcpClient.ReceiveBufferSize];

                    var length = stream.Read(forProcess.RcvBuff, offset, tcpClient.ReceiveBufferSize);
                    forProcess.RcvMsgLength = length;

                    IORequests.EnqueueAnswer(forProcess);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    //   throw;
                }



                return(retVal);
            }

            return(retVal);
        }
Exemplo n.º 4
0
 /* IORequests queue methods */
 public void EnqueueRequest(IORequestBlock iorb)
 {
     IORequests.Enqueue(iorb);
 }