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

Function sendto

co_hook_sys_call.cpp:418–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418ssize_t sendto(int socket, const void *message, size_t length,
419 int flags, const struct sockaddr *dest_addr,
420 socklen_t dest_len)
421{
422 /*
423 1.no enable sys call ? sys
424 2.( !lp || lp is non block ) ? sys
425 3.try
426 4.wait
427 5.try
428 */
429 HOOK_SYS_FUNC( sendto );
430 if( !co_is_enable_sys_hook() )
431 {
432 return g_sys_sendto_func( socket,message,length,flags,dest_addr,dest_len );
433 }
434
435 rpchook_t *lp = get_by_fd( socket );
436 if( !lp || ( O_NONBLOCK & lp->user_flag ) )
437 {
438 return g_sys_sendto_func( socket,message,length,flags,dest_addr,dest_len );
439 }
440
441 ssize_t ret = g_sys_sendto_func( socket,message,length,flags,dest_addr,dest_len );
442 if( ret < 0 && EAGAIN == errno )
443 {
444 int timeout = ( lp->write_timeout.tv_sec * 1000 )
445 + ( lp->write_timeout.tv_usec / 1000 );
446
447
448 struct pollfd pf = { 0 };
449 pf.fd = socket;
450 pf.events = ( POLLOUT | POLLERR | POLLHUP );
451 poll( &pf,1,timeout );
452
453 ret = g_sys_sendto_func( socket,message,length,flags,dest_addr,dest_len );
454
455 }
456 return ret;
457}
458
459ssize_t recvfrom(int socket, void *buffer, size_t length,
460 int flags, struct sockaddr *address,

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