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

Function write

co_hook_sys_call.cpp:365–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363
364}
365ssize_t write( int fd, const void *buf, size_t nbyte )
366{
367 HOOK_SYS_FUNC( write );
368
369 if( !co_is_enable_sys_hook() )
370 {
371 return g_sys_write_func( fd,buf,nbyte );
372 }
373 rpchook_t *lp = get_by_fd( fd );
374
375 if( !lp || ( O_NONBLOCK & lp->user_flag ) )
376 {
377 ssize_t ret = g_sys_write_func( fd,buf,nbyte );
378 return ret;
379 }
380 size_t wrotelen = 0;
381 int timeout = ( lp->write_timeout.tv_sec * 1000 )
382 + ( lp->write_timeout.tv_usec / 1000 );
383
384 ssize_t writeret = g_sys_write_func( fd,(const char*)buf + wrotelen,nbyte - wrotelen );
385
386 if (writeret == 0)
387 {
388 return writeret;
389 }
390
391 if( writeret > 0 )
392 {
393 wrotelen += writeret;
394 }
395 while( wrotelen < nbyte )
396 {
397
398 struct pollfd pf = { 0 };
399 pf.fd = fd;
400 pf.events = ( POLLOUT | POLLERR | POLLHUP );
401 poll( &pf,1,timeout );
402
403 writeret = g_sys_write_func( fd,(const char*)buf + wrotelen,nbyte - wrotelen );
404
405 if( writeret <= 0 )
406 {
407 break;
408 }
409 wrotelen += writeret ;
410 }
411 if (writeret <= 0 && wrotelen == 0)
412 {
413 return writeret;
414 }
415 return wrotelen;
416}
417
418ssize_t sendto(int socket, const void *message, size_t length,
419 int flags, const struct sockaddr *dest_addr,

Callers 2

readwrite_routineFunction · 0.85
readwrite_routineFunction · 0.85

Calls 3

co_is_enable_sys_hookFunction · 0.85
get_by_fdFunction · 0.85
pollFunction · 0.85

Tested by

no test coverage detected