Esempio n. 1
0
func (r *Receiver) handleTransfer(conn io.ReadWriter) (
	transfer.TransferResults, error,
) {
	if _, err := conn.Write([]byte("ok")); err != nil {
		return transfer.TransferResults{}, err
	}

	res := transfer.TransferResults{}
	buffer := make([]byte, 1024)

	startTime := time.Now()
	for {
		n, err := conn.Read(buffer)
		if err != nil { // done reading
			break
		}

		res.BytesSent += uint32(n)
		res.Checksum = crc32.Update(res.Checksum, crc32.IEEETable, buffer)
	}
	endTime := time.Now()

	res.Duration = endTime.Sub(startTime)

	return res, nil
}
Esempio n. 2
0
func (s *Sender) sendData(conn io.ReadWriter, size uint32, block []byte) (
	transfer.TransferResults, error,
) {
	res := transfer.TransferResults{}
	packetsAmt := uint32(size / 1024)

	startTime := time.Now()
	for i := uint32(0); i < packetsAmt; i++ {
		n, err := conn.Write(block)
		if err != nil {
			return transfer.TransferResults{}, err
		}
		res.BytesSent += uint32(n)

		res.Checksum = crc32.Update(res.Checksum, crc32.IEEETable, block)
	}
	endTime := time.Now()

	res.Duration = endTime.Sub(startTime)

	return res, nil
}