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

Function send

co_hook_sys_call.cpp:488–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488ssize_t send(int socket, const void *buffer, size_t length, int flags)
489{
490 HOOK_SYS_FUNC( send );
491
492 if( !co_is_enable_sys_hook() )
493 {
494 return g_sys_send_func( socket,buffer,length,flags );
495 }
496 rpchook_t *lp = get_by_fd( socket );
497
498 if( !lp || ( O_NONBLOCK & lp->user_flag ) )
499 {
500 return g_sys_send_func( socket,buffer,length,flags );
501 }
502 size_t wrotelen = 0;
503 int timeout = ( lp->write_timeout.tv_sec * 1000 )
504 + ( lp->write_timeout.tv_usec / 1000 );
505
506 ssize_t writeret = g_sys_send_func( socket,buffer,length,flags );
507 if (writeret == 0)
508 {
509 return writeret;
510 }
511
512 if( writeret > 0 )
513 {
514 wrotelen += writeret;
515 }
516 while( wrotelen < length )
517 {
518
519 struct pollfd pf = { 0 };
520 pf.fd = socket;
521 pf.events = ( POLLOUT | POLLERR | POLLHUP );
522 poll( &pf,1,timeout );
523
524 writeret = g_sys_send_func( socket,(const char*)buffer + wrotelen,length - wrotelen,flags );
525
526 if( writeret <= 0 )
527 {
528 break;
529 }
530 wrotelen += writeret ;
531 }
532 if (writeret <= 0 && wrotelen == 0)
533 {
534 return writeret;
535 }
536 return wrotelen;
537}
538
539ssize_t recv( int socket, void *buffer, size_t length, int flags )
540{

Callers

nothing calls this directly

Calls 3

co_is_enable_sys_hookFunction · 0.85
get_by_fdFunction · 0.85
pollFunction · 0.85

Tested by

no test coverage detected