Thread: Quick Problem Check

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by hamster_nz View Post
    Write does not have to write all the data requested, it can write just the first byte.



    This is doubly important with pipes, where the pipe can only limited amount of data. It is possible that you might be dealing with this in higher-up layers... but you are most likely expecting the writes to be an atomic "all or nothing" deal.

    read() and write() can fail with retriable/recoverable errors - e.g. SIGINT:



    The way the code at the start of the thread was written exposed you to these behaviors. This is very different to how fread()/fwrite() handle things.
    Ah so you meant that I wasn't checking the amount written/read, then yeah I get what you mean now, how 'bout this then?
    Code:
    			memset( rd2, 0, sizeof(void*) );
    			for ( bytes = 0, rdbytes = 0; rdbytes < sizeof(void*); )
    			{
    				bytes = rdpipe( pipes[PIPE_RD], rd2, sizeof(void*) - rdbytes );
    				if ( bytes >= 0 ) 
    				{
    					for ( byte = 0; byte < bytes; ++byte, ++rdbytes )
    						ptr2ptr[rdbytes] = rd2[byte];
    				}
    				else break;
    			}
    			
    			if ( bytes < 0 )
    				continue;
    I temporarily re-added the size parameter, depending on whether this method is a good idea I'll just move it inside the functions and remove the size parameter again
    Last edited by awsdert; 03-15-2021 at 05:17 PM. Reason: Forgot a parameter in my own code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick check for potential problems
    By awsdert in forum C Programming
    Replies: 28
    Last Post: 08-13-2020, 07:55 AM
  2. Quick program check
    By Nik635 in forum C Programming
    Replies: 1
    Last Post: 09-17-2015, 08:20 AM
  3. Quick check
    By SofaWolf in forum C Programming
    Replies: 6
    Last Post: 06-26-2012, 12:53 PM
  4. Need a quick check
    By Aliaks in forum C++ Programming
    Replies: 7
    Last Post: 06-05-2009, 04:57 AM
  5. Quick input check question
    By Jozrael in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2009, 07:23 AM

Tags for this Thread