Sponsored Content
Top Forums UNIX for Advanced & Expert Users problem with restarted I/O system calls Post 302593727 by jim mcnamara on Saturday 28th of January 2012 09:32:20 AM
Old 01-28-2012
You need a function that handles EINTR only. read() returns when a signal is sent.
You do not need a signal handler. write() behaves that same way.
Code:
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

ssize_t readfd(int fd, void *buffer, size_t bytes2read)
 {
     ssize_t readbytes = 0;
     ssize_t n=0;
 
     do {
         if ((n = read(fd, 
                       &((char *)buffer)[readbytes], 
                       bytes2read - readbytes)) == -1) 
         {
             if (errno == EINTR)
                 continue;
             else
             {
                 readbytes=-1;
                 break;
             }
         }
         if (!n) break;
             
         readbytes += n;
     } while (readbytes < bytes2read);
     return readbytes;
 }

Use something like readfd in place of a naked read() call.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

System Calls

What does the system call "dup" do? What is the difference between dup and dup2 I have a fair idea of what it does but I am confused when its coming down to the exact details... Please help me!:confused: (2 Replies)
Discussion started by: clickonline1
2 Replies

2. UNIX for Dummies Questions & Answers

System calls for cp and mv

Which system calls are made for operations cp and mv (2 Replies)
Discussion started by: gaurava99
2 Replies

3. UNIX for Dummies Questions & Answers

System calls?

open, creat, read, write, lseek and close Are they all primitive? :confused: *Another Question: is there a different between a system call, and an i/o system call? (2 Replies)
Discussion started by: PlunderBunny
2 Replies

4. Solaris

System calls ?

where can i find the differences in System calls between solaris and aix? also is it possible to find a comprehensive list of them? (1 Reply)
Discussion started by: TECHRAMESH
1 Replies

5. UNIX Desktop Questions & Answers

Using system calls

Hi, I'm new to UNIX system calls. Can someone share your knowledge as to how exactly system calls should be executed? Can they be typed like commands such as mkdir on the terminal itself? Also, are there any websites which will show me an example of the output to expect when a system call like... (1 Reply)
Discussion started by: ilavenil
1 Replies

6. Programming

System calls

why user is not able to switch from user to kernel mode by writing the function whose code is identical to system call. (1 Reply)
Discussion started by: joshighanshyam
1 Replies

7. BSD

system calls

what is the functions and relationship between fork,exec,wait system calls as i am a beginer just want the fundamentals. (1 Reply)
Discussion started by: sangramdas
1 Replies

8. UNIX for Dummies Questions & Answers

About system calls.

Hi all, I am new here . I want to know about system call in detail. As system calls are also function .How system identifies it.:) (2 Replies)
Discussion started by: vishwasrao
2 Replies

9. UNIX for Dummies Questions & Answers

system calls in C

Hello, how would i be able to call ps in C programming? thanks, ---------- Post updated at 01:39 AM ---------- Previous update was at 01:31 AM ---------- here's the complete system call, ps -o pid -p %d, getpit() (2 Replies)
Discussion started by: l flipboi l
2 Replies

10. UNIX for Dummies Questions & Answers

System got restarted unexpectedly

One of our Host server got restarted unexpectedly and all we got is this. Not able to guess the root cause behind this .Please help. Before restart Oct 17 19:56:06 SERVER1 kernel: suspend: event channel 75 Oct 17 19:56:10 SERVER1 smartd: smartd version 5.38 Copyright (C) 2002-8 Bruce... (3 Replies)
Discussion started by: pinga123
3 Replies
Driver-Specific modes(3)					      BrlAPI						  Driver-Specific modes(3)

NAME
Driver-Specific modes - Raw and Suspend Modes mechanism. Functions int BRLAPI_STDCALL brlapi_enterRawMode (const char *driver) int BRLAPI_STDCALL brlapi__enterRawMode (brlapi_handle_t *handle, const char *driver) int BRLAPI_STDCALL brlapi_leaveRawMode (void) int BRLAPI_STDCALL brlapi__leaveRawMode (brlapi_handle_t *handle) ssize_t BRLAPI_STDCALL brlapi_sendRaw (const void *buffer, size_t size) ssize_t BRLAPI_STDCALL brlapi__sendRaw (brlapi_handle_t *handle, const void *buffer, size_t size) ssize_t BRLAPI_STDCALL brlapi_recvRaw (void *buffer, size_t size) ssize_t BRLAPI_STDCALL brlapi__recvRaw (brlapi_handle_t *handle, void *buffer, size_t size) int BRLAPI_STDCALL brlapi_suspendDriver (const char *driver) int BRLAPI_STDCALL brlapi__suspendDriver (brlapi_handle_t *handle, const char *driver) int BRLAPI_STDCALL brlapi_resumeDriver (void) int BRLAPI_STDCALL brlapi__resumeDriver (brlapi_handle_t *handle) Detailed Description If the application wants to directly talk to the braille terminal, it should use Raw Mode. In this special mode, the driver gives the whole control of the terminal to it: brltty doesn't work any more. For this, it simply has to call brlapi_enterRawMode(), then brlapi_sendRaw() and brlapi_recvRaw(), and finally give control back thanks to brlapi_leaveRawMode(). Special care of the terminal should be taken, since one might completely trash the terminal's data, or even lock it! The application should always check for terminal's type thanks to brlapi_getDriverName(). The client can also make brltty close the driver by using brlapi_suspendDriver(), and resume it again with brlapi_resumeDriver(). This should not be used if possible: raw mode should be sufficient for any use. If not, please ask for features :) Function Documentation int BRLAPI_STDCALL brlapi__enterRawMode (brlapi_handle_t *handle, const char *driver) int BRLAPI_STDCALL brlapi__leaveRawMode (brlapi_handle_t *handle) ssize_t BRLAPI_STDCALL brlapi__recvRaw (brlapi_handle_t *handle, void *buffer, size_tsize) int BRLAPI_STDCALL brlapi__resumeDriver (brlapi_handle_t *handle) ssize_t BRLAPI_STDCALL brlapi__sendRaw (brlapi_handle_t *handle, const void *buffer, size_tsize) int BRLAPI_STDCALL brlapi__suspendDriver (brlapi_handle_t *handle, const char *driver) int BRLAPI_STDCALL brlapi_enterRawMode (const char *driver) Switch to Raw mode Parameters: driver Specifies the name of the driver for which the raw communication will be established. Returns: 0 on success, -1 on error int BRLAPI_STDCALL brlapi_leaveRawMode (void) Leave Raw mode Returns: 0 on success, -1 on error ssize_t BRLAPI_STDCALL brlapi_recvRaw (void *buffer, size_tsize) Get Raw data Parameters: buffer points on a buffer where the function will store the received data; size holds the buffer size. Returns: its size, -1 on error or signal interruption int BRLAPI_STDCALL brlapi_resumeDriver (void) Resume braille driver Returns: -1 on error ssize_t BRLAPI_STDCALL brlapi_sendRaw (const void *buffer, size_tsize) Send Raw data Parameters: buffer points on the data; size holds the packet size. Returns: size on success, -1 on error int BRLAPI_STDCALL brlapi_suspendDriver (const char *driver) Suspend braille driver Parameters: driver Specifies the name of the driver which will be suspended. Returns: -1 on error Author Generated automatically by Doxygen for BrlAPI from the source code. Version 1.0 Fri Jun 7 2013 Driver-Specific modes(3)
All times are GMT -4. The time now is 07:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy