threads / patch / 42606

patch, 2 partsMake send_client_data() return void

Subject: [PATCH 2/2] Make send_client_data() return void

## tl;dr

2 messages between Jun 16, 2016 and Jun 16, 2016. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Lukas Fleischer· Jun 14, 2016, 14:49 UTC · lore

[PATCH 1/2] Make send_sideband() return void

The send_sideband() function uses write_or_die() for writing data which immediately terminates the process on errors. If no such error occurred, send_sideband() always returned the value that was passed as fourth parameter prior to this commit. This value is already known to the caller in any case, so let's turn send_sideband() into a void function instead.

Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
---
 sideband.c    | 4 +---
 sideband.h    | 2 +-
 upload-pack.c | 6 ++++--
 3 files changed, 6 insertions(+), 6 deletions(-)
Show changes to 3 files +6 −6

sideband.c, sideband.h, upload-pack.c

diff --git a/sideband.c b/sideband.c
index 0a078c3..9504429 100644
--- a/sideband.c
+++ b/sideband.c
@@ -90,9 +90,8 @@ int recv_sideband(const char *me, int in_stream, int out)
  * fd is connected to the remote side; send the sideband data
  * over multiplexed packet stream.
  */
-ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
+void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
 {
-	ssize_t ssz = sz;
 	const char *p = data;
 
 	while (sz) {
@@ -114,5 +113,4 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
 		p += n;
 		sz -= n;
 	}
-	return ssz;
 }
diff --git a/sideband.h b/sideband.h
index e46bed0..7a8146f 100644
--- a/sideband.h
+++ b/sideband.h
@@ -5,6 +5,6 @@
 #define SIDEBAND_REMOTE_ERROR -1
 
 int recv_sideband(const char *me, int in_stream, int out);
-ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
+void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
 
 #endif
diff --git a/upload-pack.c b/upload-pack.c
index 56d101f..cab71b1 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -67,8 +67,10 @@ static void reset_timeout(void)
 
 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 {
-	if (use_sideband)
-		return send_sideband(1, fd, data, sz, use_sideband);
+	if (use_sideband) {
+		send_sideband(1, fd, data, sz, use_sideband);
+		return sz;
+	}
 	if (fd == 3)
 		/* emergency quit */
 		fd = 2;
-- 
2.8.3
Lukas Fleischer· Jun 14, 2016, 14:49 UTC · re: Lukas Fleischer · lore

The send_client_data() function uses write_or_die() for writing data which immediately terminates the process on errors. If no such error occurred, send_client_data() always returned the value that was passed as third parameter prior to this commit. This value is already known to the caller in any case, so let's turn send_client_data() into a void function instead.

Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
---
 upload-pack.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
Show changes to upload-pack.c +5 −10
diff --git a/upload-pack.c b/upload-pack.c
index cab71b1..432d585 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -65,11 +65,11 @@ static void reset_timeout(void)
 	alarm(timeout);
 }
 
-static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
+static void send_client_data(int fd, const char *data, ssize_t sz)
 {
 	if (use_sideband) {
 		send_sideband(1, fd, data, sz, use_sideband);
-		return sz;
+		return;
 	}
 	if (fd == 3)
 		/* emergency quit */
@@ -77,10 +77,9 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 	if (fd == 2) {
 		/* XXX: are we happy to lose stuff here? */
 		xwrite(fd, data, sz);
-		return sz;
+		return;
 	}
 	write_or_die(fd, data, sz);
-	return sz;
 }
 
 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
@@ -245,9 +244,7 @@ static void create_pack_file(void)
 			}
 			else
 				buffered = -1;
-			sz = send_client_data(1, data, sz);
-			if (sz < 0)
-				goto fail;
+			send_client_data(1, data, sz);
 		}
 
 		/*
@@ -274,9 +271,7 @@ static void create_pack_file(void)
 	/* flush the data */
 	if (0 <= buffered) {
 		data[0] = buffered;
-		sz = send_client_data(1, data, 1);
-		if (sz < 0)
-			goto fail;
+		send_client_data(1, data, 1);
 		fprintf(stderr, "flushed.\n");
 	}
 	if (use_sideband)
-- 
2.8.3

← back to recent threads