Exemple #1
0
        protected override void beginRead(incommingReadDelegate callback)
        {
            later = new Thread(() =>
            {
                long i = 1;
                while (true)
                {
                    lock (later)
                    {
                        if (!isRunning)
                        {
                            break;
                        }
                    }

                    callback("dummy read " + i);
                    i++;

                    try
                    {
                        Thread.Sleep(2000);
                    }
                    catch (ThreadInterruptedException) { }
                }
            });

            later.Start();
        }
Exemple #2
0
        protected override void beginRead(incommingReadDelegate callback)
        {
            byte[]  buffer = new byte[CHUNK_SIZE];
            ReadAcc acc    = new ReadAcc(0, false, false, new LinkedList <char>());

            SocketExceptionContainer(() =>
            {
                connection.BeginReceive(buffer, 0, CHUNK_SIZE, SocketFlags.None,
                                        (IAsyncResult ar) => { onReadOp(buffer, acc, callback); }, null);
            });
        }
Exemple #3
0
        private void onReadOp(byte[] buffer, ReadAcc a, incommingReadDelegate callback)
        {
            a.wasInBody = a.wasInBody || a.inBody;

            foreach (byte b in buffer)
            {
                if (a.inBody)
                {
                    a.msg.AddLast(Convert.ToChar(b));

                    a.fLoc   = b == FLANK[a.fLoc - 1] ? a.fLoc - 1 : CHUNK_SIZE;
                    a.inBody = a.fLoc != 0;
                }
                else
                {
                    a.fLoc   = b == FLANK[a.fLoc] ? a.fLoc + 1 : 0;
                    a.inBody = a.fLoc == CHUNK_SIZE;
                }
            }

            if (!a.wasInBody || a.inBody)
            {
                SocketExceptionContainer(() =>
                {
                    connection.BeginReceive(buffer, 0, CHUNK_SIZE, SocketFlags.None,
                                            (IAsyncResult ar) => { onReadOp(buffer, a, callback); }, null);
                });
            }
            else
            {
                for (int i = 0; i < CHUNK_SIZE; i++)
                {
                    a.msg.RemoveLast();
                }
                string ret = new string(a.msg.ToArray()).Trim();

                callback(ret);
            }
        }
Exemple #4
0
 protected abstract void beginRead(incommingReadDelegate callback);