Beispiel #1
0
        protected void UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
        {
            RCAsyncState state = (RCAsyncState)e.UserState;

            if (e.Error != null)
            {
                state.Runner.Report(state.Closure, e.Error);
            }
            RCSymbolScalar id   = (RCSymbolScalar)state.Other;
            string         text = _client.Encoding.GetString(e.Result);

            // TODO: make this into a real object with headers and body and stuff.
            _inbox.Add(id, new RCString(text));
        }
Beispiel #2
0
        protected void ReceiveCompleted(IAsyncResult result)
        {
            int count = 0;

            try
            {
                count = _socket.EndReceive(result);
                if (count > 0)
                {
                    long    sid = -1;
                    long    ignore;
                    RCBlock message = _buffer.CompleteReceive(_openState.Runner,
                                                              count,
                                                              _handle,
                                                              sid,
                                                              out ignore);
                    RCSymbol id = (RCSymbol)message.Get("id");
                    // Console.Out.WriteLine ("Client receiving {0}, message:{1}", id, message);
                    if (message != null)
                    {
                        _inbox.Add(id[0], message);
                    }
                    _socket.BeginReceive(
                        _buffer.RecvBuffer,
                        _buffer.Read,
                        _buffer.RecvBuffer.Length - _buffer.Read,
                        SocketFlags.None,
                        new AsyncCallback(ReceiveCompleted),
                        null);
                }
            }
            catch (Exception ex)
            {
                _openState.Runner.Report(_openState.Closure, ex);
            }
            finally
            {
                if (count == 0)
                {
                    _socket.Close(1000);
                    RCSystem.Log.Record(_openState.Closure, "socket", _handle, "closed", "");
                }
            }
        }