MCPcopy Create free account
hub / github.com/acl-dev/acl / sys_read

Function sys_read

lib_acl/src/stdlib/acl_vstream.c:271–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271static int sys_read(ACL_VSTREAM *in, void *buf, size_t size)
272{
273 int read_cnt, nagain = 0;
274
275 /* clear the read_ready flag first: we shouldn't clear the flag
276 * after read() API such as read_fn called, because in some case,
277 * the read_ready flag maybe set 1 again in order to invoke the
278 * IO event in non-blocking mode.
279 */
280 in->read_ready = 0;
281
282 if (in->type == ACL_VSTREAM_TYPE_FILE) {
283 if (ACL_VSTREAM_FILE(in) == ACL_FILE_INVALID) {
284 /* in->read_ready = 0; */
285 return -1;
286 }
287 } else if (ACL_VSTREAM_SOCK(in) == ACL_SOCKET_INVALID) {
288 /* in->read_ready = 0; */
289 return -1;
290 }
291
292#ifndef SAFE_COPY
293#define SAFE_COPY(x, y) ACL_SAFE_STRNCPY((x), (y), sizeof((x)))
294#endif
295
296AGAIN:
297
298 /* ���ϵͳ����� */
299 acl_set_error(0);
300
301 if (in->type == ACL_VSTREAM_TYPE_FILE) {
302 read_cnt = in->fread_fn(ACL_VSTREAM_FILE(in), buf, size,
303 in->rw_timeout, in, in->context);
304 if (in->read_cnt > 0) {
305 in->sys_offset += in->read_cnt;
306 }
307 } else {
308 read_cnt = in->read_fn(ACL_VSTREAM_SOCK(in), buf, size,
309 in->rw_timeout, in, in->context);
310 }
311
312 if (read_cnt > 0) {
313 in->flag &= ~ACL_VSTREAM_FLAG_BAD;
314 in->errnum = 0;
315 in->total_read_cnt += read_cnt;
316
317 return read_cnt;
318 } else if (read_cnt == 0) {
319 in->flag = ACL_VSTREAM_FLAG_EOF;
320 in->errnum = 0;
321
322 return 0;
323 }
324
325 in->errnum = acl_last_error();
326
327 if (in->errnum == ACL_EINTR) {
328 if (nagain++ < 5) {

Callers 1

read_to_bufferFunction · 0.85

Calls 3

acl_set_errorFunction · 0.85
acl_last_errorFunction · 0.85
acl_msg_errorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…