MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / Open

Method Open

modules/core/profile/internal/tracy/common/TracySocket.cpp:563–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561}
562
563bool UdpBroadcast::Open( const char* addr, uint16_t port )
564{
565 assert( m_sock == -1 );
566
567 struct addrinfo hints;
568 struct addrinfo *res, *ptr;
569
570 memset( &hints, 0, sizeof( hints ) );
571 hints.ai_family = AF_INET;
572 hints.ai_socktype = SOCK_DGRAM;
573
574 char portbuf[32];
575 sprintf( portbuf, "%" PRIu16, port );
576
577 if( getaddrinfo( addr, portbuf, &hints, &res ) != 0 ) return false;
578 int sock = 0;
579 for( ptr = res; ptr; ptr = ptr->ai_next )
580 {
581 if( ( sock = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol ) ) == -1 ) continue;
582#if defined __APPLE__
583 int val = 1;
584 setsockopt( sock, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof( val ) );
585#endif
586#if defined _WIN32
587 unsigned long broadcast = 1;
588 if( setsockopt( sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof( broadcast ) ) == -1 )
589#else
590 int broadcast = 1;
591 if( setsockopt( sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof( broadcast ) ) == -1 )
592#endif
593 {
594#ifdef _WIN32
595 closesocket( sock );
596#else
597 close( sock );
598#endif
599 continue;
600 }
601 break;
602 }
603 freeaddrinfo( res );
604 if( !ptr ) return false;
605
606 m_sock = sock;
607 inet_pton( AF_INET, addr, &m_addr );
608 return true;
609}
610
611void UdpBroadcast::Close()
612{

Callers 1

WorkerMethod · 0.45

Calls 2

memsetFunction · 0.85
closesocketFunction · 0.50

Tested by

no test coverage detected