Skip to content

Commit f164ea7

Browse files
committed
simulator/ssh: WriteRandom client method simplification
WriteRandom() now simply returns a WriteResponse{}. The simulation module performs further porcessing (ie. channel sends).
1 parent e97b3ce commit f164ea7

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

simulator/ssh-transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *SSHTransfer) simulate(
104104
ch <- res
105105
return
106106
}
107-
c.WriteRandom(handle, sendSize, ch)
107+
ch <- c.WriteRandom(handle, sendSize)
108108
c.Teardown()
109109
}
110110

simulator/ssh/client.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,13 @@ func (c *Client) SendClose(handle string) (*fxp.Status, error) {
240240
return closeResp, nil
241241
}
242242

243-
// writeRandom writes toSend bytes of 'random' data to the server. A WriteResponse is created
244-
// and sent down the channel ch.
245-
func (c *Client) WriteRandom(handleStr string, toSend bytesize.ByteSize, ch chan<- WriteResponse) {
243+
// WriteRandom writes toSend bytes of 'random' data to the server. A WriteResponse is created
244+
// and returned.
245+
func (c *Client) WriteRandom(handleStr string, toSend bytesize.ByteSize) WriteResponse {
246246
// First, send an open request.
247247
openResp, err := c.SendOpen(handleStr, os.O_CREATE)
248248
if err != nil {
249-
ch <- WriteResponse{c.Name, 0, "", err}
250-
return
249+
return WriteResponse{c.Name, 0, "", err}
251250
}
252251
handle := openResp.Handle
253252
// 1MB writes.
@@ -274,11 +273,10 @@ func (c *Client) WriteRandom(handleStr string, toSend bytesize.ByteSize, ch chan
274273
totalDataBytesSent += dataBytesSent
275274
}
276275
if err != nil {
277-
ch <- WriteResponse{c.Name, totalDataBytesSent, handle, fmt.Errorf("failed transfer: %w", err)}
278-
return
276+
return WriteResponse{c.Name, totalDataBytesSent, handle, fmt.Errorf("failed transfer: %w", err)}
279277
}
280278
}
281279
// Close the handle. We don't care about the response, just the error.
282280
_, err = c.SendClose(handle)
283-
ch <- WriteResponse{c.Name, totalDataBytesSent, handle, err}
281+
return WriteResponse{c.Name, totalDataBytesSent, handle, err}
284282
}

0 commit comments

Comments
 (0)