Mercurial > remote-gamepad-server
comparison restartOp.c @ 0:e70ea46d6073
Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 22 Feb 2015 01:38:06 +0100 |
parents | |
children | f362b20de51e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e70ea46d6073 |
---|---|
1 /* | |
2 Signal interruptible fonctions handlers | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <unistd.h> | |
7 #include <sys/wait.h> | |
8 #include <sys/ipc.h> | |
9 #include <sys/sem.h> | |
10 #include <sys/msg.h> | |
11 #include <errno.h> | |
12 | |
13 #include "restartOp.h" | |
14 | |
15 /********************************************************/ | |
16 /* fork */ | |
17 /********************************************************/ | |
18 pid_t fork_rs(void){ | |
19 pid_t result; | |
20 | |
21 do{ | |
22 result = fork(); | |
23 }while((result == -1) && (errno == EAGAIN)); | |
24 | |
25 return result; | |
26 } | |
27 | |
28 /********************************************************/ | |
29 /* wait, waitpid */ | |
30 /********************************************************/ | |
31 /* | |
32 pid_t wait_rs(int *status) | |
33 { | |
34 pid_t endPid; | |
35 | |
36 do { | |
37 endPid=wait(status); | |
38 } while ((endPid==-1) && (errno==EINTR)); | |
39 | |
40 return endPid; | |
41 } | |
42 */ | |
43 /* | |
44 pid_t waitpid_rs(pid_t pid, int *status, int options) | |
45 { | |
46 pid_t endPid; | |
47 | |
48 do { | |
49 endPid=waitpid(pid,status,options); | |
50 } while ((endPid==-1) && (errno==EINTR)); | |
51 | |
52 return endPid; | |
53 } | |
54 */ | |
55 | |
56 /********************************************************/ | |
57 /* sleep */ | |
58 /********************************************************/ | |
59 | |
60 unsigned int sleep_rs(unsigned int seconds) | |
61 { | |
62 int nbSecondsElapsed = 0; | |
63 | |
64 do { | |
65 | |
66 seconds = seconds - nbSecondsElapsed; | |
67 | |
68 nbSecondsElapsed = sleep(seconds); | |
69 | |
70 } while (nbSecondsElapsed!=0); | |
71 | |
72 return 0; // Zero if the requested time has elapsed | |
73 } | |
74 | |
75 | |
76 /********************************************************/ | |
77 /* read, write, close */ | |
78 /********************************************************/ | |
79 /* | |
80 ssize_t read_rs(int fd, void *buf, size_t len) | |
81 { | |
82 ssize_t returnValue = 0; | |
83 | |
84 do { | |
85 returnValue = read(fd,buf,len); | |
86 } while ((returnValue==-1) && (errno==EINTR)); | |
87 | |
88 return returnValue; | |
89 } | |
90 */ | |
91 /* | |
92 ssize_t write_rs(int fd, const void *buf, size_t count) | |
93 { | |
94 ssize_t returnValue = 0; | |
95 | |
96 do { | |
97 returnValue = write(fd,buf,count); | |
98 } while ((returnValue==-1) && (errno==EINTR)); | |
99 | |
100 return returnValue; | |
101 } | |
102 */ | |
103 /* | |
104 int close_rs(int fd) | |
105 { | |
106 int returnValue = 0; | |
107 | |
108 do { | |
109 returnValue = close(fd); | |
110 } while ((returnValue==-1) && (errno==EINTR)); | |
111 | |
112 return returnValue; | |
113 } | |
114 */ | |
115 | |
116 /********************************************************/ | |
117 /* dup, dup2 */ | |
118 /********************************************************/ | |
119 /* | |
120 int dup_rs(int oldfd) | |
121 { | |
122 int returnValue = 0; | |
123 | |
124 do { | |
125 returnValue = dup(oldfd); | |
126 } while ((returnValue==-1) && (errno==EINTR)); | |
127 | |
128 return returnValue; | |
129 } | |
130 */ | |
131 /* | |
132 int dup2_rs(int oldfd, int newfd) | |
133 { | |
134 int returnValue = 0; | |
135 | |
136 do { | |
137 returnValue = dup2(oldfd,newfd); | |
138 } while ((returnValue==-1) && (errno==EINTR)); | |
139 | |
140 return returnValue; | |
141 } | |
142 */ | |
143 | |
144 /********************************************************/ | |
145 /* semop */ | |
146 /********************************************************/ | |
147 /* | |
148 int semop_rs(int semid, struct sembuf *sops,unsigned nsops) | |
149 { | |
150 int returnValue = 0; | |
151 | |
152 do { | |
153 returnValue = semop(semid,sops,nsops); | |
154 } while ((returnValue==-1) && (errno==EINTR)); | |
155 | |
156 return returnValue; | |
157 } | |
158 */ | |
159 | |
160 /********************************************************/ | |
161 /* msgsnd, msgrcv */ | |
162 /********************************************************/ | |
163 /* | |
164 int msgsnd_rs(int msqid, void *msgp, int msgsz, int msgflg) | |
165 { | |
166 int returnValue = 0; | |
167 | |
168 do { | |
169 returnValue = msgsnd(msqid,msgp,msgsz,msgflg); | |
170 } while ((returnValue==-1) && (errno==EINTR)); | |
171 | |
172 return returnValue; | |
173 } | |
174 */ | |
175 /* | |
176 int msgrcv_rs(int msqid, void *msgp, int msgsz,long msgtyp,int msgflg) | |
177 { | |
178 int returnValue = 0; | |
179 | |
180 do { | |
181 returnValue = msgrcv(msqid,msgp,msgsz,msgtyp,msgflg); | |
182 } while ((returnValue==-1) && (errno==EINTR)); | |
183 | |
184 return returnValue; | |
185 } | |
186 */ | |
187 | |
188 /********************************************************/ | |
189 /* connect, accept */ | |
190 /********************************************************/ | |
191 /* | |
192 int connect_rs(int sockfd, struct sockaddr *serv_addr, socklen_t addrlen) | |
193 { | |
194 int returnValue = 0; | |
195 | |
196 do { | |
197 returnValue = connect(sockfd,serv_addr,addrlen); | |
198 } while ((returnValue==-1) && (errno==EINTR)); | |
199 | |
200 return returnValue; | |
201 } | |
202 */ | |
203 /* | |
204 int accept_rs(int sockfd, struct sockaddr *addr, socklen_t *addrlen) | |
205 { | |
206 int returnValue = 0; | |
207 int addrlenSaved = *addrlen; | |
208 | |
209 do { | |
210 *addrlen = addrlenSaved; | |
211 returnValue = accept(sockfd,addr,addrlen); | |
212 } while ((returnValue==-1) && (errno==EINTR)); | |
213 | |
214 return returnValue; | |
215 } | |
216 */ | |
217 | |
218 /********************************************************/ | |
219 /* recv, send (TCP ou UDP avec pseudo-connexions) */ | |
220 /********************************************************/ | |
221 /* | |
222 ssize_t recv_rs(int sockfd, void *buf, size_t len, int flags) | |
223 { | |
224 int returnValue = 0; | |
225 | |
226 do { | |
227 returnValue = recv(sockfd,buf,len,flags); | |
228 } while ((returnValue==-1) && (errno==EINTR)); | |
229 | |
230 return returnValue; | |
231 } | |
232 */ | |
233 /* | |
234 ssize_t send_rs(int sockfd, const void *buf, size_t count, int flags) | |
235 { | |
236 int returnValue = 0; | |
237 | |
238 do { | |
239 returnValue = send(sockfd,buf,count,flags); | |
240 } while ((returnValue==-1) && (errno==EINTR)); | |
241 | |
242 return returnValue; | |
243 } | |
244 */ | |
245 | |
246 /********************************************************/ | |
247 /* recvfrom, sendto (UDP) */ | |
248 /********************************************************/ | |
249 | |
250 ssize_t recvfrom_rs(int sockfd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen){ | |
251 ssize_t returnValue = 0; | |
252 do{ | |
253 returnValue = recvfrom(sockfd, buf, len, flags, from, fromlen); | |
254 }while( (returnValue == -1) && (errno == EINTR) ); | |
255 | |
256 return returnValue; | |
257 } | |
258 | |
259 /* | |
260 ssize_t sendto_rs(int sockfd, const void *msg, size_t count, int flags, | |
261 const struct sockaddr *to, socklen_t tolen) | |
262 { | |
263 ssize_t returnValue = 0; | |
264 do { | |
265 returnValue = sendto(sockfd,msg,count,flags,to,tolen); | |
266 } while ((returnValue==-1) && (errno==EINTR)); | |
267 | |
268 return returnValue; | |
269 } | |
270 */ |