Message ID | e671894b4c0419138e66270aa9699053bdd504be.1612208747.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Simple IPC Mechanism | expand |
On Mon, Feb 01, 2021 at 07:45:36PM +0000, Jeff Hostetler via GitGitGadget wrote: > From: Jeff Hostetler <jeffhost@microsoft.com> > > Create version of `write_packetized_from_buf()` that takes a scratch buffer > argument rather than assuming a static buffer. This will be used later as > we make packet-line writing more thread-safe. OK, this is extending the changes from the first patch... > int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) > { > static struct packet_scratch_space scratch; > + > + return write_packetized_from_buf2(src_in, len, fd_out, &scratch); > +} > + > +int write_packetized_from_buf2(const char *src_in, size_t len, int fd_out, > + struct packet_scratch_space *scratch) Oof, that name. I know we are guilty of a lot of "foo_1()" helpers for foo(), but they are usually internal static functions that don't get spread around. This one is a public function. Something like "_with_scratch" might be a bit more descriptive. Though given that there is exactly one caller of the original currently, I'd be tempted to say that it should just learn the scratch-space argument. (All of this is moot, of course, if you follow either of my suggestions from the earlier patch to drop the need for this scratch space entirely). -Peff
diff --git a/pkt-line.c b/pkt-line.c index 14af049cd9c..5d86354cbeb 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -278,6 +278,13 @@ int write_packetized_from_fd(int fd_in, int fd_out) int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) { static struct packet_scratch_space scratch; + + return write_packetized_from_buf2(src_in, len, fd_out, &scratch); +} + +int write_packetized_from_buf2(const char *src_in, size_t len, int fd_out, + struct packet_scratch_space *scratch) +{ int err = 0; size_t bytes_written = 0; size_t bytes_to_write; @@ -289,7 +296,7 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) bytes_to_write = len - bytes_written; if (bytes_to_write == 0) break; - err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write, &scratch); + err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write, scratch); bytes_written += bytes_to_write; } if (!err) diff --git a/pkt-line.h b/pkt-line.h index 4ccd6f88926..f1d5625e91f 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -41,6 +41,8 @@ int packet_flush_gently(int fd); int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3))); int write_packetized_from_fd(int fd_in, int fd_out); int write_packetized_from_buf(const char *src_in, size_t len, int fd_out); +int write_packetized_from_buf2(const char *src_in, size_t len, int fd_out, + struct packet_scratch_space *scratch); /* * Read a packetized line into the buffer, which must be at least size bytes