static void err(const char *m, ...) { va_list va; va_start(va, m); vdie("error", m, va); va_end(va); exit(4); }
static void ice(const char *m, ...) { va_list va; va_start(va, m); vdie("internal complier error", m, va); va_end(va); exit(3); }
void cmpl_bailout(char *fmt, ...) { va_list ap; cmpl_dump(); va_start(ap, fmt); vdie(fmt, ap); va_end(ap); }
void die(const char *fmt, ...) { va_list l; va_start(l, fmt); vdie(NULL, fmt, l); /* FIXME: this is called before current_fname etc is init'd */ va_end(l); /* unreachable */ }
void die_at(const struct where *w, const char *fmt, ...) { va_list l; va_start(l, fmt); vdie(w, fmt, l); va_end(l); /* unreachable */ }
/*PRINTFLIKE1*/ void die(const char *format, ...) { va_list alist; va_start(alist, format); vdie(format, alist); va_end(alist); }
void vnlisten( u32 port, vncallback cb ){ int s; struct addrinfo* res = NULL; struct addrinfo hnts; if( pvnscks == NULL ) pvninit(); vzero( hnts ); hnts.ai_family = AF_INET; hnts.ai_socktype = SOCK_STREAM; hnts.ai_protocol = IPPROTO_TCP; hnts.ai_flags = AI_PASSIVE; s = getaddrinfo( NULL, vintToString( port, 0 ), &hnts, &res ); if( s ){ vdie( "getaddrinfo failed!" ); } { SOCKET cs; cs = socket( res->ai_family, res->ai_socktype, res->ai_protocol ); if( cs == INVALID_SOCKET ){ freeaddrinfo( res ); vdie( "socket failed!" ); } { int i = 1; setsockopt( cs, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *)&i, sizeof( int ) ); } pvncheck( "bind failed", bind( cs, res->ai_addr, (int)res->ai_addrlen ), &cs, res ); freeaddrinfo( res ); pvncheck( "listen failed", listen( cs, SOMAXCONN ), &cs, NULL ); pvnaddsock( &cs, cb ); vlogInfo( "Now listening on port " ); vlogInfo( vintToString( port, 0 ) ); vlogInfo( "\n" ); } }
void pvninit( void ){ int s; s = WSAStartup( MAKEWORD(2,2), &pvndata ); if( s ){ vdie( "WSAStartup failed!" ); return; } vlogInfo( "vninit completed\n" ); if( !pvnqs ){ pvnqs = vmalloc( 0 ); pvnnqs = 0; } pvnscks = vsmalloc( sizeof( SOCKET ) ); pvncons = vsmalloc( sizeof( SOCKET ) ); pvncbs = vsmalloc( sizeof( vncallback* ) ); pvnccbs = vsmalloc( sizeof( vncallback* ) ); pvncids = vsmalloc( sizeof( u32 ) ); pvnfids = vsmalloc( sizeof( u32 ) ); pvntimes = vsmalloc( sizeof( f32 ) ); }
void pvncheck( const u8* msg, int s, SOCKET* cs, struct addrinfo* ai ){ if( s == SOCKET_ERROR ){ int err = WSAGetLastError(); if( err != 10053 && err != 10054 ){ u32 em = vmalloc( 0 ); vappendString( em, msg ); vappendString( em, "\nError " ); vappendInt( em, err, 0 ); vappendString( em, ": " ); { u8* ls; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (LPTSTR)&ls, 0, NULL ); vappendString( em, ls ); LocalFree( ls ); } if( cs != NULL ) closesocket( *cs ); if( ai != NULL ) freeaddrinfo( ai ); vdie( vmem( em ) ); } } }
// die without printing system error void die(char* format, ...) { va_list args; va_start(args, format); errno = 0; vdie(format, args); }