Example #1
0
  /////////////
  /// Public Methods
  ////////////
 
  /**
   * Implementing the interface from ITransferManager
   * When a request is allowed, we set up the state and
   * start acting
   */
  public Status Allow(Request req, System.IO.Stream data) {
 
    Status stat = new Status(req, data);
    lock( _sync ) { 
      _tid_to_status[req.LocalTID] = stat; 
    }

    if( req.Reqtype == Opcode.ReadReq ) {
      /**
       * We are starting a read request here.  We send the
       * first data packet as an ack of this request
       */
      StreamState rs = new StreamState();
      int new_block = 1;
      stat.StartBlock(new_block, rs);
      rs.Stat = stat;
      rs.Block = new_block;
      rs.Data = new byte[ stat.Request.Blksize ];
      rs.Offset = 0;
      stat.Data.BeginRead(rs.Data, rs.Offset, stat.Request.Blksize,
			  new AsyncCallback(this.ReadHandler),
			  rs);
    }
    else if( req.Reqtype == Opcode.WriteReq ) {
      SendAck(req, 0);
    }
    else {
      /**
       * This can't happen because we would only process Read or Write
       * requests
       * @todo add error handling if ReqType is non-sensical
       */
    }
    return stat;
  }
Example #2
0
  /**
   * Write all the data from the current position in data until the
   * end of the stream
   */
  public Status Put(Stream data, Address target, string filename) {
    //First we make a TID for this transfer:
    short tid = GetNextTID();
    Request req;
    //Send the Length if we can:
    if( data.CanSeek ) {
      req = new Request(tid, DefaultTID, Opcode.WriteReq,
		                target, filename, data.Length);
    }
    else {
      req = new Request(tid, DefaultTID, Opcode.WriteReq,
		                target, filename);
    }
    SendRequest(req);
    Status stat = new Status(req, data);
    lock( _sync ) { 
      _tid_to_status[tid] = stat; 
    }
    return stat;
  }