MCPcopy Create free account
hub / github.com/Tencent/libco / read

Function read

co_hook_sys_call.cpp:330–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328 return ret;
329}
330ssize_t read( int fd, void *buf, size_t nbyte )
331{
332 HOOK_SYS_FUNC( read );
333
334 if( !co_is_enable_sys_hook() )
335 {
336 return g_sys_read_func( fd,buf,nbyte );
337 }
338 rpchook_t *lp = get_by_fd( fd );
339
340 if( !lp || ( O_NONBLOCK & lp->user_flag ) )
341 {
342 ssize_t ret = g_sys_read_func( fd,buf,nbyte );
343 return ret;
344 }
345 int timeout = ( lp->read_timeout.tv_sec * 1000 )
346 + ( lp->read_timeout.tv_usec / 1000 );
347
348 struct pollfd pf = { 0 };
349 pf.fd = fd;
350 pf.events = ( POLLIN | POLLERR | POLLHUP );
351
352 int pollret = poll( &pf,1,timeout );
353
354 ssize_t readret = g_sys_read_func( fd,(char*)buf ,nbyte );
355
356 if( readret < 0 )
357 {
358 co_log_err("CO_ERR: read fd %d ret %ld errno %d poll ret %d timeout %d",
359 fd,readret,errno,pollret,timeout);
360 }
361
362 return readret;
363
364}
365ssize_t write( int fd, const void *buf, size_t nbyte )
366{
367 HOOK_SYS_FUNC( write );

Callers 2

readwrite_routineFunction · 0.85
readwrite_routineFunction · 0.85

Calls 4

co_is_enable_sys_hookFunction · 0.85
get_by_fdFunction · 0.85
pollFunction · 0.85
co_log_errFunction · 0.85

Tested by

no test coverage detected