From a5d6603b22bfb2332b084726633f6d13abc1d484 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 20 Jun 2014 20:23:37 +0200 Subject: [PATCH] Add comments to the code. --- src/process2.c | 16 ++++++++++++++-- src/process3.c | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/process2.c b/src/process2.c index 327ad8e..4db50e0 100644 --- a/src/process2.c +++ b/src/process2.c @@ -17,12 +17,24 @@ int main(void) { /** Named pipe used to communicate with process3 */ char * write_pipe = "/tmp/process2pipe"; + /** Descriptor of input pipe */ int read_descriptor; + + /** Descriptor of output pipe */ int write_descriptor; - + + /** + * Buffer used for storing data from input pipe. + * Data is stored in chunks of BUFFER_STEP size. + * If data during reading is bigger than this value, then number of + * characters is saved, and buffer is cleared for reading another chunk. + */ char buffer[BUFFER_STEP]; - + + /** Index used when iterating buffer */ int i = 0; + + /** Stores number of bytes read from input pipe in current iteration */ ssize_t count = 0; /* Reading from process1 */ diff --git a/src/process3.c b/src/process3.c index b2fe61c..dfa30db 100644 --- a/src/process3.c +++ b/src/process3.c @@ -11,18 +11,18 @@ int main(void) { /** Named pipe used to communicate with process2 */ char * read_pipe = "/tmp/process2pipe"; + /** Descriptor of input pipe */ int read_descriptor; - + + /** Buffer used for storing data from input pipe */ int buffer = 0; - int i = 0; + /** Stores number of bytes read from input pipe in current iteration */ ssize_t count = 0; /* Reading from process2 */ read_descriptor = open(read_pipe, O_RDONLY); - int number_of_characters = 0; - while(1) { /* Read data from input pipe */ count = read(read_descriptor, &buffer, sizeof(int)); -- 2.30.2