Exemple #1
0
        public TcpSendState Send(RCRunner runner,
                                 RCClosure closure,
                                 long cid,
                                 RCBlock message)
        {
            TcpSendState correlation = new TcpSendState(_handle, cid, message);
            RCAsyncState state       = new RCAsyncState(runner, closure, correlation);

            byte[] payload = Encoding.ASCII.GetBytes(message.ToString());
            // If other items are queued in the outbox Add will return false.
            // This message should be sent after the others.
            if (_outbox.Add(state))
            {
                // Send will add the header to the payload.
                // This is something I will probably want to change by adding some kind of
                // serializer/formatter abstraction.
                int size = _buffer.PrepareSend(cid, payload);
                _socket.BeginSend(
                    _buffer.SendBuffer,
                    0,
                    size,
                    SocketFlags.None,
                    new AsyncCallback(SendCompleted),
                    state);
                // Console.Out.WriteLine ("Server sending {0}", correlation.Id);
            }
            return(correlation);
        }
Exemple #2
0
        public override TcpSendState Send(RCRunner runner, RCClosure closure, RCBlock message)
        {
            long cid = Interlocked.Increment(ref _cid);

            // Console.Out.WriteLine ("New Cid:{0}", cid);
            byte[]       payload     = _protocol.Serialize(this, message);
            TcpSendState correlation = new TcpSendState(_handle, cid, message);
            RCAsyncState state       = new RCAsyncState(runner, closure, correlation);

            if (_outbox.Add(state))
            {
                // Send will add the header to the payload.
                // This is something I will probably want to change by adding some kind of
                // serializer/formatter abstraction.
                int size = _buffer.PrepareSend(correlation.Id, payload);
                _socket.BeginSend(
                    _buffer.SendBuffer,
                    0,
                    size,
                    SocketFlags.None,
                    new AsyncCallback(SendCompleted),
                    state);
                // Console.Out.WriteLine ("Client sending {0}", correlation.Id);
            }
            else
            {
                // Console.Out.WriteLine ("Another message has to go first");
            }
            return(correlation);
        }